# totalElements is missing in javascript c8y/client

**URL:** https://community.cumulocity.com/t/totalelements-is-missing-in-javascript-c8y-client/3097
**Category:** Forum
**Tags:** cumulocity
**Created:** [December 4, 2024, 1:17pm UTC](https://community.cumulocity.com/t/totalelements-is-missing-in-javascript-c8y-client/3097 "2024-12-04T13:17:18Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![MagnusAkermanAspire](https://avatars.discourse-cdn.com/v4/letter/m/8e7dd6/32.png) [@MagnusAkermanAspire](https://community.cumulocity.com/u/MagnusAkermanAspire)
#### Post date: [December 4, 2024, 1:17pm UTC](https://community.cumulocity.com/t/totalelements-is-missing-in-javascript-c8y-client/3097/1 "2024-12-04T13:17:18Z")

</div>

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

@c8y/client@1020.18.3

#### _Detailed explanation of the problem:_

In Cumulocity API, when requesting for a list of e.g. alarms you can use the withTotalElements parameter that will respond including totalElements in the statistics. However, using the @c8y/client for Javascript, there seems to be no way of getting that information from the same request. (pageSize and totalPages is not enough information).

---

<div class="post-metadata">

### Author: ![Tristan\_Bastian](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/tristan_bastian/32/18259_2.png) [@Tristan\_Bastian](https://community.cumulocity.com/u/Tristan_Bastian)
#### Post date: [December 4, 2024, 2:59pm UTC](https://community.cumulocity.com/t/totalelements-is-missing-in-javascript-c8y-client/3097/2 "2024-12-04T14:59:59Z")

</div>

Hi @MagnusAkermanAspire,

this is currently not available as part of the Paging object, but will be available in a future release.

You can however just implement this on your own:

```auto
import { Client, BasicAuth } from '@c8y/client';

const user = '<your-user>';
const password = '<your-password>';
const baseUrl = 'https://<your-domain>';

const client = new Client(new BasicAuth({ user, password }), baseUrl);

async function withTotalElements() {
  const response = await client.core.fetch('/inventory/managedObjects', {
    params: { withTotalElements: true }
  });
  if (!response.ok) {
    throw new Error(`HTTP error! status: ${response.status}`);
  }
  const responseBody = await response.json();
  const { totalElements } = responseBody.statistics;
  console.log(totalElements);
}

```

Within an Web SDK based Angular application you could even just use dependency injection:

```auto
import { FetchClient } from '@c8y/client';
[...]
  constructor(private fetchClient: FetchClient) {}

  async withTotalElements() {
    const response = await this.fetchClient.fetch('/inventory/managedObjects', {
      params: { withTotalElements: true }
    });
    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`);
    }
    const responseBody = await response.json();
    const { totalElements } = responseBody.statistics;
    console.log(totalElements);
  }
[...]

```

Regards,  
Tristan

---

<div class="post-metadata">

### Author: ![Tristan\_Bastian](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/tristan_bastian/32/18259_2.png) [@Tristan\_Bastian](https://community.cumulocity.com/u/Tristan_Bastian)
#### Post date: [December 5, 2024, 10:01am UTC](https://community.cumulocity.com/t/totalelements-is-missing-in-javascript-c8y-client/3097/3 "2024-12-05T10:01:56Z")

</div>

FYI: Version `1021.14.0` of the `@c8y/client` package will include the `totalElements` attribute on the paging object.

---

<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: [June 3, 2025, 10:02am UTC](https://community.cumulocity.com/t/totalelements-is-missing-in-javascript-c8y-client/3097/4 "2025-06-03T10:02:36Z")

</div>

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