Count Groups

Returns an approximate count of groups. If the count exceeds 100,000, it is updated every 24 hours. The `refreshed_at` property of the `count` object is a timestamp that indicates when the count was last updated. **Note**: When the count exceeds 100,000, `refreshed_at` may occasionally be null. This indicates that the count is being updated in the background, and the `value` property of the `count` object is limited to 100,000 until the update is complete. #### Allowed For * Admins * Agents

Script zendesk Verified

by hugo697 ยท 11/7/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 377 days ago
1
type Zendesk = {
2
  username: string;
3
  password: string;
4
  subdomain: string;
5
};
6
/**
7
 * Count Groups
8
 * Returns an approximate count of groups. If the count exceeds 100,000, it is updated every 24 hours.
9

10
The `refreshed_at` property of the `count` object is a timestamp that indicates when the count was last updated.
11

12
**Note**: When the count exceeds 100,000, `refreshed_at` may occasionally be null. This indicates that the count is being updated in the background, and the `value` property of the `count` object is limited to 100,000 until the update is complete.
13

14
#### Allowed For
15

16
* Admins
17
* Agents
18

19
 */
20
export async function main(auth: Zendesk) {
21
  const url = new URL(
22
    `https://${auth.subdomain}.zendesk.com/api/v2/groups/count`
23
  );
24

25
  const response = await fetch(url, {
26
    method: "GET",
27
    headers: {
28
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
29
    },
30
    body: undefined,
31
  });
32
  if (!response.ok) {
33
    const text = await response.text();
34
    throw new Error(`${response.status} ${text}`);
35
  }
36
  return await response.json();
37
}
38