API Query - Not always authorising?

Hi,
I’ve got a script which authorises machines on our ZeroTier network via API.

This works… Sporadically.

The script (in one call) sets name, description and ticks the authorised box. Sometimes though, it won’t tick the box, but the other calls work

These are the relevant lines of code in the script (Powershell)

// Previous lines pull the api key, date, network ID, member ID etc
$action = "Auth" //testing purposes
if($action -eq "Auth"){
  $action = "true"
  $humanaction = "Authorised"
} else {
  $action = "false"
  $humanaction = "DeAuthorised"
}
$name = hostname

$desc = "'$humanaction NinjaOne $currentdate'"
$body = @{
"name"=$name;
"description"=$desc;
"config"=@{
	"authorized"=$action;
};
}
$json = ConvertTo-Json $body
Invoke-RestMethod -Uri https://my.zerotier.com/api/network/$networkID/member/$memberID -Body $json -Headers $headers -Method POST

$action is either true or false (I’ve also tried True/False and 1/0) depending on whether the script is invoked as “auth” or “deauth”.

Interestingly, the docs show that it should return the authorisation state in lower case
image
but it’s returning it in Sentence case instead

So, couple of questions

  1. Do we have any idea why this doesn’t work (all the time)? I built the script, tested it, then I gave it to the rest of the team and they sometimes come to me and say it’s not working (but not every time)
  2. Does the documentation need updating to correct the upper/lower response?
  3. I’d expect if the body was invalid that it would make NO changes, but it’s successfully changing the name and description.

I suspect the issue is related to your handling of the property “authorized”. In the ZeroTier API, including the example you showed, that property is a boolean (i.e., the literal values true and false) not a string. When you create your request body JSON, though, you appear to be assigning a value of either "true" or "false" (a string).

That’s also why the response is being printed differently on the console. A PowerShell boolean is rendered as titlecase True or False after being converted to a native value.

That’s the fix, thanks. Not sure why I didn’t spot that myself but :man_shrugging:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.