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

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:

/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:

"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:

"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!

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

$ 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.

image

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