TECHZEN Zenoss User Community ARCHIVE  

HOW the heck....Set/move to Location using API

Subject: HOW the heck....Set/move to Location using API
Author: [Not Specified]
Posted: 2017-06-06 10:30

Can someone please tell me how to move a device to a location....I have tried
zenoss_api "device_router" "DeviceRouter" "moveDevices" '{"uids":["/zport/dmd/Devices/Server/Windows/devices/testdevice"],"hashcheck":"","uid":"/zport/dmd/Locations/Webservers"}'

It keeps telling me moveDevices() takes at least 3 arguments

Funny enough though I change moveDevices to removeDevices and test it by moving the device in the GUI and the remove api call works fine?????


Subject: RE: HOW the heck....Set/move to Location using API
Author: Tim Caiazza
Posted: 2017-06-07 23:03

Have you tried looking at the API requests when you do this via the web browser?  See the attached screenshot of what happens I move a device around. 

It appears the format of the data you want to post is 

{
'uids': [...],                       # a list of all the uids of the devices to move
'range': []                          # An empty list
'target': "/zport/dmd/Locations/..." # the location to move devices to
}

I was able to successfully move a device around using this syntax.

------------------------------
Tim Caiazza
------------------------------


Subject: RE: HOW the heck....Set/move to Location using API
Author: [Not Specified]
Posted: 2017-06-08 07:58

Thanks! How did you make the request thru the browser and watch the response?


Subject: RE: HOW the heck....Set/move to Location using API
Author: Tim Caiazza
Posted: 2017-06-08 09:30

In chrome under tools, there is a menu called Developer under there select Developer tools.  Firefox and Safari all have something similar just google how to use those.  So the developer tools will bring up something like this 
Note: I'm on the network tab, which shows all the network requests your browser is making to the web page, and since all the web ui stuff in zenoss uses the REST API we can figure out how everything is done if we catch the correct api request.  So with this screen open move a device to a new location, and you should see a request named device_router.  Click that request and there will be a new pop up that shows the request that is made.  That will look somethign like this



The request payload is the data that is sent to zenoss, and this is what you have to pass on in your REST API request.

------------------------------
Tim Caiazza
------------------------------


Subject: RE: HOW the heck....Set/move to Location using API
Author: [Not Specified]
Posted: 2017-06-08 11:08

THANK YOU!!!!!! That just saved me so much time!

------------------------------
-TC
------------------------------


Subject: RE: HOW the heck....Set/move to Location using API
Author: Sachin Tewari
Posted: 2017-07-04 01:57

What is it that you used finally that made it possible to move devices?

------------------------------
Sachin
------------------------------


Subject: RE: HOW the heck....Set/move to Location using API
Author: Sachin Tewari
Posted: 2017-07-04 08:37

Done! Thanks

------------------------------
Sachin Tewari
------------------------------


< Previous
Calculated Performance ZenPack - using attributes and methods of components
  Next
Newly Created ZenPack Export
>