List Activities

Lists ticket activities in the last 30 days affecting the agent making the request. Also sideloads the following arrays of user records: - actors - All actors involved in the listed activities - users - All users involved in the listed activities #### Pagination - Cursor pagination (recommended) - Offset pagination See Pagination. Returns a maximum of 100 records per page. #### 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
 * List Activities
8
 * Lists ticket activities in the last 30 days affecting the agent making the request.
9
Also sideloads the following arrays of user records:
10

11
- actors - All actors involved in the listed activities
12
- users - All users involved in the listed activities
13

14
#### Pagination
15

16
- Cursor pagination (recommended)
17
- Offset pagination
18

19
See Pagination.
20

21
Returns a maximum of 100 records per page.
22

23
#### Allowed For
24

25
* Agents
26

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