Assign device to group using the API

Hi,

Is there a way to assign a device to a group using the API ?

I found that there is a POST request (POST /inventory/managedObjects//childAssets) to do that, but I could not find how to retrieve the groupID ?

Thanks,
Fourkane

@Fourkane_Irki,

Can you try to {{url}}/inventory/managedObjects?fragmentType=c8y_IsDeviceGroup

you should get all group IDs.

Hi Gyan,

The API request looks like working but only one page is returned (a subset of the group IDs). If there an API pagination, is there a way to request all pages at the same time ?

Thanks

@Fourkane_Irki,

Good to know , it is working . Yes , you can do pagination. Please refer the docs for " Query result paging"
https://cumulocity.com/guides/reference/rest-implementation/

Hi Gyan,

Do you know if we can do the same thing using MQTT protocol ?
I could not find the topic fot that in the documentation.

Thanks

AFAIK,I am not aware of any such implementation in MQTT. The MQTT implementation of Cumulocity IoT is specifically designed for device communication. Therefore, it tries to remove as much unnecessary logic from the client side as possible.

Using the REST (or SmartREST) protocol requires to know the ID of every object, alarm and operation you want to update. Hence, a client needs to keep a state of these IDs. For example, if it creates an alarm, it needs to know the ID of the alarm so it can clear it afterwards.

With the MQTT implementation we want to reduce the logic required on the device to do such actions and move the logic to the server.