Count Tickets in Views

Returns the ticket count of each view in a list of views. Accepts up to 20 view ids per request. For the ticket count of a single view, see [Count Tickets in View](#count-tickets-in-view). Only returns values for personal and shared views accessible to the user performing the request. This endpoint is rate limited to 6 requests every 5 minutes. #### Allowed For * 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 Tickets in Views
8
 * Returns the ticket count of each view in a list of views. Accepts up to 20 view ids per request. For the ticket count of a single view, see [Count Tickets in View](#count-tickets-in-view).
9

10
Only returns values for personal and shared views accessible to the user performing the request.
11

12
This endpoint is rate limited to 6 requests every 5 minutes.
13

14
#### Allowed For
15

16
* Agents
17

18
 */
19
export async function main(auth: Zendesk, ids: string | undefined) {
20
  const url = new URL(
21
    `https://${auth.subdomain}.zendesk.com/api/v2/views/count_many`
22
  );
23
  for (const [k, v] of [["ids", ids]]) {
24
    if (v !== undefined && v !== "") {
25
      url.searchParams.append(k, v);
26
    }
27
  }
28
  const response = await fetch(url, {
29
    method: "GET",
30
    headers: {
31
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
32
    },
33
    body: undefined,
34
  });
35
  if (!response.ok) {
36
    const text = await response.text();
37
    throw new Error(`${response.status} ${text}`);
38
  }
39
  return await response.json();
40
}
41