# Missing \`totalElements\` in API Response When Using \`onlyRoots=true\` Parameter

**URL:** https://community.cumulocity.com/t/missing-totalelements-in-api-response-when-using-onlyroots-true-parameter/7731
**Category:** Forum
**Tags:** cumulocity
**Created:** [April 8, 2024, 3:07pm UTC](https://community.cumulocity.com/t/missing-totalelements-in-api-response-when-using-onlyroots-true-parameter/7731 "2024-04-08T15:07:54Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Nam\_Nhat\_Pham](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/nam_nhat_pham/32/510_2.png) [@Nam\_Nhat\_Pham](https://community.cumulocity.com/u/Nam_Nhat_Pham)
#### Post date: [April 8, 2024, 3:07pm UTC](https://community.cumulocity.com/t/missing-totalelements-in-api-response-when-using-onlyroots-true-parameter/7731/1 "2024-04-08T15:07:54Z")

</div>

#### _Cumulocity platform version:_

1018.435.0

#### _Detailed explanation of the problem:_

I’ve been working with an API endpoint for fetching inventory managed objects, and I encountered an inconsistency in the API response that I’m hoping to get some insight into. The endpoint I’m using is structured as follows:

```auto
/inventory/managedObjects?withTotalPages=true&withTotalElements=true&onlyRoots=true

```

When I include the parameter `onlyRoots=true` in my request, the response’s `statistics` object looks like this:

```json
"statistics": {
    "totalPages": 1,
    "pageSize": 1000,
    "currentPage": 1
}

```

However, if I remove the `onlyRoots=true` parameter or set it to false, I receive a more detailed `statistics` object, including the `totalElements` field:

```json
"statistics": {
    "totalPages": 1,
    "pageSize": 1000,
    "currentPage": 1,
    "totalElements": 216
}

```

I was expecting the `totalElements` field to be present regardless of the `onlyRoots` parameter, as it provides crucial information about the total number of items available.

**Does anyone know if this is intended behavior or not?**

Thank you in advance for your help!

---

<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: [April 8, 2024, 3:16pm UTC](https://community.cumulocity.com/t/missing-totalelements-in-api-response-when-using-onlyroots-true-parameter/7731/2 "2024-04-08T15:16:52Z")

</div>

Hi - it might be worth knowing your BE version as I could not reproduce it on eu-latest:

```sh
$ curl -skX 'GET' -H 'Accept: application/json' -H "Authorization: Bearer $TOKEN" 'https://example.eu-latest.cumulocity.com/inventory/managedObjects?withTotalElements=true&withTotalPages=true&onlyRoots=true' | jq .statistics
{
  "totalPages": 3380,
  "pageSize": 5,
  "currentPage": 1,
  "totalElements": 16896
}

$ curl -skX 'GET' -H 'Accept: application/json' -H "Authorization: Bearer $TOKEN" 'https://example.eu-latest.cumulocity.com/inventory/managedObjects?withTotalElements=true&withTotalPages=true' | jq .statistics
{
  "totalPages": 3413,
  "pageSize": 5,
  "currentPage": 1,
  "totalElements": 17065
}

```

> I was expecting the totalElements field to be present regardless of the onlyRoots parameter, as it provides crucial information about the total number of items available.

An alternative is to set pageSize to 1. In this case numer of pages = number of elements.

---

<div class="post-metadata">

### Author: ![Nam\_Nhat\_Pham](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/nam_nhat_pham/32/510_2.png) [@Nam\_Nhat\_Pham](https://community.cumulocity.com/u/Nam_Nhat_Pham)
#### Post date: [April 8, 2024, 4:41pm UTC](https://community.cumulocity.com/t/missing-totalelements-in-api-response-when-using-onlyroots-true-parameter/7731/3 "2024-04-08T16:41:32Z")

</div>

![image](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/b/b/bb8f894a3a04d9b3c2ee63f077aa164bc585569b.png)

Here is the current version on tenant that I am using: 1018.435.0

---

<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: [October 5, 2024, 4:41pm UTC](https://community.cumulocity.com/t/missing-totalelements-in-api-response-when-using-onlyroots-true-parameter/7731/4 "2024-10-05T16:41:36Z")

</div>

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