Add device to group API
I'm trying to find the right way to add an existing device to an existing group via the REST API.
I've tried PATCHing / PUTing the hostGroupIds field of the device but that doesnt work, and I get the following.
"errmsg" : "Property(name=hostGroupIds) cannot be found in device(id=1504)'s own property"
Should I add the group ID to the device, or can I edit the devices in a Group via the API?
cuotos
Posted 9 years ago·Last reply 9 years ago
2 comments
cuotos
OP9 years agoExactly what I wanted. thanks.
I've just found https://www.logicmonitor.com/support/rest-api-developers-guide/devices/update-a-device/#PATCH which for some reason I misses yesterday.
Sarah Terry
·9 years agoThe recommended method is to update the hostGroupIds field for the device. If you only want to change the device's group membership, a PATCH request makes the most sense. If you're adding the device to a group, but want it to remain in the existing groups, you'll likely want to make a GET request first, and just tack the new group id onto the end. Here's an example of updating a device's group membership (in Python):
Note that the hostGroupIds field is called out in the patchFields query parameter, as well as in the payload. Is this what you attempted to do? If so, if you share your code I can help identify what went wrong.
Thanks!
Sarah