# Count of devices in inventory

**URL:** https://community.cumulocity.com/t/count-of-devices-in-inventory/2097
**Category:** Forum
**Tags:** cumulocity
**Created:** [September 21, 2023, 8:06pm UTC](https://community.cumulocity.com/t/count-of-devices-in-inventory/2097 "2023-09-21T20:06:25Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![david.presuhn](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/david.presuhn/32/32123_2.png) [@david.presuhn](https://community.cumulocity.com/u/david.presuhn)
#### Post date: [September 21, 2023, 8:06pm UTC](https://community.cumulocity.com/t/count-of-devices-in-inventory/2097/1 "2023-09-21T20:06:25Z")

</div>

#### _ **Product/components** used and **version/fix** level:_

Cumulocity 10.17

#### _Detailed explanation of the problem:_

I’m looking for a way to query and get a count of total devices in a subtenancy. I know I can query inventory/managedObjects?fragmentType=c8y\_IsDevice&withTotalPages=True&pageSize=100 and get the totalPages, navigate to pageNumber= in the query string and iterate through and count the devices in that page and then multiply the pagesize \* (totalPages-1) + devices counted in the last page. but that seems really fiddly and wonder if there’s a parameter to the inventory to merely return a count.

I didn’t see anything in [https://cumulocity.com/api/core/10.17.0/#tag/Managed-objects](https://cumulocity.com/api/core/10.17.0/#tag/Managed-objects)

#### _Error messages / **full error** message screenshot / **log** file:_

No error message

#### _Question related to a **free trial** , or to a **production (customer)** instance?_

Related to a hosted cloud production instance

---

<div class="post-metadata">

### Author: ![Korbinian\_Butz](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/korbinian_butz/32/10473_2.png) [@Korbinian\_Butz](https://community.cumulocity.com/u/Korbinian_Butz)
#### Post date: [September 21, 2023, 8:39pm UTC](https://community.cumulocity.com/t/count-of-devices-in-inventory/2097/2 "2023-09-21T20:39:27Z")

</div>

Hi,

you can add `withTotalElements=true` to your query. Then your response will contain a `statistics.totalElements` field then:

```json
{
  "managedObjects": [
    { ... }, { ... }, { ... }, { ... }, { ... }
  ],
  "next": "https://examples.cumulocity.com/inventory/managedObjects?withTotalElements=true&pageSize=5&fragmentType=c8y_IsDevice&currentPage=2",
  "self": "https://examples.cumulocity.com/inventory/managedObjects?withTotalElements=true&pageSize=5&fragmentType=c8y_IsDevice&currentPage=1",
  "statistics": {
    "currentPage": 1,
    "pageSize": 5,
    "totalElements": 83245 <= total count of query results
  }
}

```

It’s listed as API parameter for the [retrieve all managed objects](https://cumulocity.com/api/core/10.17.0/#operation/getManagedObjectCollectionResource) endpoint.

Alternatively, if it’s just about the count, you could set your pageSize to 1 so that totalPages=totalCount. Also, when stating withTotalPages the pageSize shouldbe part of the statistics fragment - so you wouldn’t need to extract that from the URL. But I think `withTotalElements` is the parameter you’re looking for.

---

<div class="post-metadata">

### Author: ![david.presuhn](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/david.presuhn/32/32123_2.png) [@david.presuhn](https://community.cumulocity.com/u/david.presuhn)
#### Post date: [September 21, 2023, 8:52pm UTC](https://community.cumulocity.com/t/count-of-devices-in-inventory/2097/3 "2023-09-21T20:52:13Z")

</div>

Ah, there it is! Yes, I find it now. Thanks for pointing that out!

---

<div class="post-metadata">

### Author: ![Robert\_Neale](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/robert_neale/32/31965_2.png) [@Robert\_Neale](https://community.cumulocity.com/u/Robert_Neale)
#### Post date: [September 22, 2023, 7:57am UTC](https://community.cumulocity.com/t/count-of-devices-in-inventory/2097/4 "2023-09-22T07:57:00Z")

</div>

You could also do pageSize=1 - the the returned totalPages indicates the number of devices.

---

<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: [March 20, 2024, 7:57am UTC](https://community.cumulocity.com/t/count-of-devices-in-inventory/2097/5 "2024-03-20T07:57:03Z")

</div>

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