List Ticket Metric Events

Returns ticket metric events that occurred on or after the start time. Cursor pagination returns a maximum of 100 records per page. Events are listed in chronological order. If the results are not paginated, events will be returned as a time-based incremental export. See Time-based incremental exports. #### Pagination * Cursor pagination * No pagination See Pagination. #### Allowed For * Admins

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
 * List Ticket Metric Events
8
 * Returns ticket metric events that occurred on or after the start time.
9

10
Cursor pagination returns a maximum of 100 records per page. Events are listed in chronological order.
11

12
If the results are not paginated, events will be returned as a time-based incremental export.
13

14
See Time-based incremental exports.
15

16
#### Pagination
17
* Cursor pagination
18
* No pagination
19

20
See Pagination.
21

22
#### Allowed For
23

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