Skip to main content

Central API Examples (Legacy Central)

Legacy Central API

These examples use the Legacy Central API. For New Central, use Service Account tokens with the same API endpoints.

In the examples below use the following placeholder variables to match commonly-needed parameters:

info

See the API Tokens guide for detailed instructions on creating Service Account tokens for New Central or personal API tokens for Legacy Central.

PowerShell Users

If you encounter an error like "System.String and System.Collections.IDictionary" when using curl within PowerShell, this is due to an alias. curl in PowerShell is a wrapper for Invoke-WebRequest which has different parameter syntax than curl on non-Windows operating systems. You can either use curl.exe directly (if available) or use the native Invoke-WebRequest cmdlet.

Exporting Data from the Central API

The examples below are intended to run in a system terminal, and require the following command-line tools:

Each of them will fetch network information and produce CSV as output. You can then import that CSV into your choice of database, spreadsheet, or configuration-management tool(s).

List current networks ( shell curl )

curl -s -H "Authorization: token $ZT_TOKEN" \
"https://api.zerotier.com/api/v1/network" \
| jq '.[] | [
.id,
.config.name,
.config.description,
.totalMemberCount,
.config.creationTime,
.config.ipAssignmentPools[0].ipRangeStart,
.config.ipAssignmentPools[0].ipRangeEnd
]' \
| jq -rs '.[] | @csv'

List current networks ( Powershell Invoke-WebRequest )

$ZT_TOKEN = "your_zerotier_token_here"

$headers = @{
"Authorization" = "token $ZT_TOKEN"
}

$response = Invoke-WebRequest -Uri "https://api.zerotier.com/api/v1/network" -Headers $headers

$networks = $response.Content | ConvertFrom-Json

$result = $networks | ForEach-Object {
[PSCustomObject]@{
id = $_.id
name = $_.config.name
description = $_.config.description
totalMemberCount = $_.totalMemberCount
creationTime = $_.config.creationTime
ipRangeStart = $_.config.ipAssignmentPools[0].ipRangeStart
ipRangeEnd = $_.config.ipAssignmentPools[0].ipRangeEnd
}
} | ConvertTo-Csv -NoTypeInformation

$result | ForEach-Object { $_ -replace '"', '' }

Authorize and Deauthorize Network Members

Authorize a network member ( shell curl )

curl -H "Authorization: token $ZT_TOKEN" -X POST \
"https://api.zerotier.com/api/v1/network/$NWID/member/$MEMBER_ID" \
--data '{"config": {"authorized": true}}'

Authorize a network member ( Powershell Invoke-WebRequest )

$ZT_TOKEN = "your_zerotier_token_here"
$NWID = "your_network_id_here"
$MEMBER_ID = "your_member_id_here"

$headers = @{
"Authorization" = "token $ZT_TOKEN"
}

$body = @{
config = @{
authorized = $true
}
} | ConvertTo-Json

Invoke-WebRequest -Uri "https://api.zerotier.com/api/v1/network/$NWID/member/$MEMBER_ID" `
-Method Post -Headers $headers -Body $body -ContentType "application/json"

Set the Network MTU

The network MTU is configured through the API (there is no field for it in the Central UI). It sets the MTU on each member's ZeroTier virtual network adapter. ZeroTier's default is 2800. You can raise it (for example to 9000 for jumbo frames), but every member and the physical path between them must support the larger value or traffic may be silently dropped.

The endpoints differ between New Central and Legacy Central — choose the matching tab.

New Central uses the v2 API at central.zerotier.com with a Service Account token passed as a Bearer token.

Set the MTU on New Central ( shell curl )

curl -H "Authorization: Bearer $ZT_TOKEN" -X POST \
"https://central.zerotier.com/api/v2/network/$NWID" \
--data '{"config": {"mtu": 2800}}'

Set the MTU on New Central ( Powershell Invoke-WebRequest )

$ZT_TOKEN = "your_zerotier_token_here"
$NWID = "your_network_id_here"

$headers = @{
"Authorization" = "Bearer $ZT_TOKEN"
}

$body = @{
config = @{
mtu = 2800
}
} | ConvertTo-Json

Invoke-WebRequest -Uri "https://central.zerotier.com/api/v2/network/$NWID" `
-Method Post -Headers $headers -Body $body -ContentType "application/json"