# How to query for all devices inside a group

**URL:** <https://community.cumulocity.com/t/how-to-query-for-all-devices-inside-a-group/7117>\
**Category:** Forum\
**Tags:** cumulocity\
**Created:** [February 28, 2023, 7:10am UTC](https://community.cumulocity.com/t/how-to-query-for-all-devices-inside-a-group/7117 "2023-02-28T07:10:03Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bishan\_T\_Prasad](https://avatars.discourse-cdn.com/v4/letter/b/3ab097/32.png) [@Bishan\_T\_Prasad](https://community.cumulocity.com/u/Bishan_T_Prasad)\
**Post date:** [February 28, 2023, 7:10am UTC](https://community.cumulocity.com/t/how-to-query-for-all-devices-inside-a-group/7117/1 "2023-02-28T07:10:03Z")

</div>

Hi All,

We have created hierarchical structure of assets and device with 1+ levels of hierarchy.  
For eg:  
Subsystem - group  
IAQ - subgroup  
device 1 - device  
subgroup2 - subgroup  
device 2 - device

So with the above structure if i have to retrieve all the devices within the Subsystem group, is there any way i can retrieve all the devices in one call?

Currently, im getting the getting the child assets of the group and checking if the type is device or group. if it is group then i’m querying it again to get all the child assets which is a inefficient way to get all devices. So please advice me how can i get the result in an efficient way.

---

<div class="post-metadata">

**Author:** ![Marco\_Stoffel](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/marco_stoffel/32/19453_2.png) [@Marco\_Stoffel](https://community.cumulocity.com/u/Marco_Stoffel)\
**Post date:** [February 28, 2023, 9:48am UTC](https://community.cumulocity.com/t/how-to-query-for-all-devices-inside-a-group/7117/2 "2023-02-28T09:48:38Z")

</div>

Hi,

sorry, I don’t think there is another way. This should be implemented in the backend though…

Regards,

Marco

---

<div class="post-metadata">

**Author:** ![Christian\_Guether1](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/christian_guether1/32/14848_2.png) [@Christian\_Guether1](https://community.cumulocity.com/u/Christian_Guether1)\
**Post date:** [February 28, 2023, 9:57am UTC](https://community.cumulocity.com/t/how-to-query-for-all-devices-inside-a-group/7117/3 "2023-02-28T09:57:26Z")

</div>

Hi,

I think you will need to use `bygroupid()` and the query language as described [here](https://cumulocity.com/api/core/#section/Supported-functions) to construct your query to get all devices in one single query.

Best regards  
Christian

---

<div class="post-metadata">

**Author:** ![Bishan\_T\_Prasad](https://avatars.discourse-cdn.com/v4/letter/b/3ab097/32.png) [@Bishan\_T\_Prasad](https://community.cumulocity.com/u/Bishan_T_Prasad)\
**Post date:** [February 28, 2023, 10:35am UTC](https://community.cumulocity.com/t/how-to-query-for-all-devices-inside-a-group/7117/5 "2023-02-28T10:35:52Z")

</div>

Hi Christian,  
Thanks for the response. If I have to make use of bygroupid() then I should know all the subgroup ids in prior right?

---

<div class="post-metadata">

**Author:** ![Christian\_Guether1](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/christian_guether1/32/14848_2.png) [@Christian\_Guether1](https://community.cumulocity.com/u/Christian_Guether1)\
**Post date:** [February 28, 2023, 10:37am UTC](https://community.cumulocity.com/t/how-to-query-for-all-devices-inside-a-group/7117/6 "2023-02-28T10:37:41Z")

</div>

Yes, you would need to know the underlying subgroups and their ids.

---

<div class="post-metadata">

**Author:** ![Bishan\_T\_Prasad](https://avatars.discourse-cdn.com/v4/letter/b/3ab097/32.png) [@Bishan\_T\_Prasad](https://community.cumulocity.com/u/Bishan_T_Prasad)\
**Post date:** [February 28, 2023, 1:09pm UTC](https://community.cumulocity.com/t/how-to-query-for-all-devices-inside-a-group/7117/7 "2023-02-28T13:09:34Z")

</div>

Ok. Got it. thanks

 ![~WRD0000.jpg](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/5/2/52d5f1c08649212fe6768d2cacdcf8df711810d9.jpeg)

![image001.png](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/a/8/a87b6b11fc928737ad2dbd12da3a006a3a205d55.png)

 ![image002.png](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/c/f/cf1b917ed7c6f7002675b6d2085708ab46bd3863.png)

![image003.png](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/6/5/65744658a72aed06e95d96a2113499f4669f0265.png)

![image005.png](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/2/3/23ca7d938b07ded9a33c446728fea44b516d299c.png)

![image006.png](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/d/5/d55f312a337c351dd5f393b63ad636a866718307.png)

![image007.png](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/7/5/759d5313a8df46b009ec4b45704aa3d86dc870a8.png)

![image008.jpg](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/optimized/2X/d/d969ada2aef25ab0d07ed5d54e61cbbc18ff288a_2_690x85.jpeg)

![image004.png](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/6/0/6057172a7934415d5df4e1764199d3ba3e1d9e68.png)

---

<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:** [August 27, 2023, 1:10pm UTC](https://community.cumulocity.com/t/how-to-query-for-all-devices-inside-a-group/7117/8 "2023-08-27T13:10:24Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
