Forum Discussion

Ian_Fraser's avatar
2 years ago

API PUT to rename a collector device displayname errors randomly

Hi all - hopefully one of the gurus on here can help me out (i have searched and couldn't find an answer)

I'm using PowerShell to install the Collector on some of our Domain Controllers- following this for the cmdline

After install, the device displayname is (numeric value of the ID), which is the same device as the collector.

Because of this, I'm trying to rename the device using a REST PUT to the device/devices/ID path. This IS working, but I have to wait a seemingly random amount of time to get a 200 status success  code returned. I can confirm the device displayname is updated correctly at this point. Otherwsie, after the install, I am constantly getting a 1403 returned from my GET and subsequent PUT invoke-restmethod.

It's within a fairly sizable window (maybe around 30 mins?) that it seems to work with a 200 returned.  I'm not making any other API calls with this token in that time and hitting limits.

I'm editing the Displayname of the device in code (just reading the device ID and using GET of the entire device config into a PSobject, changing its displayname, and writing it back out to JSON and using an Invoke-RestMethod to write back.

Any help much appreciated!

3 Replies

  • Basically, I don't like PUT because LM requires you have the device ID to do the PUT. That basically negates the usefulness of a PUT because if you have the ID you might as well PATCH.

  • Haven't had any experience when doing my puts. However, I steer away from puts because i disagree with how they are instrumented in the API (soapbox rant available upon request). Why not patch? Then you're just patching the name? You can then avoid the get because the collector install should get you the related device id. With the device id and the new name, you should be able to patch in one step.

  • Thanks Stuart - I did try patch but possibly i was using a different API token back then which might have been a different root cause of fail. I will revert back and give that a go - thanks for your help. I'd be interested on your viewpoints on the API implementation if you ever get on your soapbox :)/emoticons/smile@2x.png 2x" title=":)" width="20" />