# Assign device to group using the API

**URL:** <https://community.cumulocity.com/t/assign-device-to-group-using-the-api/1047>\
**Category:** Forum\
**Tags:** cumulocity-edge, cumulocity\
**Created:** [August 12, 2020, 8:07pm UTC](https://community.cumulocity.com/t/assign-device-to-group-using-the-api/1047 "2020-08-12T20:07:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fourkane\_Irki](https://avatars.discourse-cdn.com/v4/letter/f/2acd7d/32.png) [@Fourkane\_Irki](https://community.cumulocity.com/u/Fourkane_Irki)\
**Post date:** [August 12, 2020, 8:07pm UTC](https://community.cumulocity.com/t/assign-device-to-group-using-the-api/1047/1 "2020-08-12T20:07:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Gyan\_Awasthi1](https://avatars.discourse-cdn.com/v4/letter/g/eada6e/32.png) [@Gyan\_Awasthi1](https://community.cumulocity.com/u/Gyan_Awasthi1)\
**Post date:** [August 13, 2020, 2:25am UTC](https://community.cumulocity.com/t/assign-device-to-group-using-the-api/1047/2 "2020-08-13T02:25:59Z")

</div>

@Fourkane_Irki,

Can you try to {{url}}/inventory/managedObjects?fragmentType=c8y\_IsDeviceGroup

you should get all group IDs.

---

<div class="post-metadata">

**Author:** ![Fourkane\_Irki](https://avatars.discourse-cdn.com/v4/letter/f/2acd7d/32.png) [@Fourkane\_Irki](https://community.cumulocity.com/u/Fourkane_Irki)\
**Post date:** [August 14, 2020, 1:29am UTC](https://community.cumulocity.com/t/assign-device-to-group-using-the-api/1047/3 "2020-08-14T01:29:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Gyan\_Awasthi1](https://avatars.discourse-cdn.com/v4/letter/g/eada6e/32.png) [@Gyan\_Awasthi1](https://community.cumulocity.com/u/Gyan_Awasthi1)\
**Post date:** [August 14, 2020, 2:11am UTC](https://community.cumulocity.com/t/assign-device-to-group-using-the-api/1047/4 "2020-08-14T02:11:48Z")

</div>

@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/](https://cumulocity.com/guides/reference/rest-implementation/)

---

<div class="post-metadata">

**Author:** ![Fourkane\_Irki](https://avatars.discourse-cdn.com/v4/letter/f/2acd7d/32.png) [@Fourkane\_Irki](https://community.cumulocity.com/u/Fourkane_Irki)\
**Post date:** [August 25, 2020, 11:59pm UTC](https://community.cumulocity.com/t/assign-device-to-group-using-the-api/1047/5 "2020-08-25T23:59:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Gyan\_Awasthi1](https://avatars.discourse-cdn.com/v4/letter/g/eada6e/32.png) [@Gyan\_Awasthi1](https://community.cumulocity.com/u/Gyan_Awasthi1)\
**Post date:** [August 26, 2020, 2:09am UTC](https://community.cumulocity.com/t/assign-device-to-group-using-the-api/1047/6 "2020-08-26T02:09:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/system/32/31990_2.png) [@system](https://community.cumulocity.com/u/system)\
**Post date:** [April 2, 2021, 3:45pm UTC](https://community.cumulocity.com/t/assign-device-to-group-using-the-api/1047/7 "2021-04-02T15:45:03Z")

</div>


