Hi there,
So I have embarked on a project to remove all nodes from a network. The only way to do this it seems is by use of the API.
I wrote out an API calls to get all the node information for each member and got a count just shy of 8500.
Ok, thats a lot, no worries. Whats the rate limit? for me 20 API calls per second. Ok so limiting it to 1 API call a second is more than sufficient, cool.
If I select a nodeID, and manually call a deletion… Woo it deletes.
So the premise and theory check out. So how do I delete them all, I would need to loop through all 8500 members and call a deletion.
Well here we go
# Replace NETWORK_ID with the ID of the network you want to remove nodes from
# Replace AUTH_TOKEN with your auth token
$networkID = "PUT NETWORK ID HERE"
$authToken = "PUT AUTHTOKEN HERE"
$headers = @{
"Authorization" = "Bearer $authToken"
}
# Get a list of all nodes in the network
$nodes = (Invoke-WebRequest -Uri "https://api.zerotier.com/api/v1/network/$networkID/member" -Headers $headers).Content | ConvertFrom-Json
$nodes = $nodes | sort-object -Property lastOnline
# Loop through each node and remove it from the network
foreach ($node in $nodes) {
Invoke-WebRequest -Uri "https://api.zerotier.com/api/v1/network/$networkID/member/$($node.id)" -Method DELETE -Headers $headers
start-sleep 1
}
Left it running overnight… still shy of 8500.
I really don’t get it.
Has anyone else run into this problem?
p.s. Its Powershell