1 | type Zendesk = { |
2 | username: string; |
3 | password: string; |
4 | subdomain: string; |
5 | }; |
6 | |
7 | * List Audit Logs |
8 | * #### Allowed For |
9 |
|
10 | * Admins on accounts that have audit log access |
11 |
|
12 | #### Pagination |
13 |
|
14 | * Cursor pagination (recommended) |
15 | * Offset pagination |
16 |
|
17 | See Pagination. |
18 |
|
19 | Returns a maximum of 100 records per page. |
20 |
|
21 | */ |
22 | export async function main( |
23 | auth: Zendesk, |
24 | filter_source_type_: string | undefined, |
25 | filter_source_id_: string | undefined, |
26 | filter_actor_id_: string | undefined, |
27 | filter_ip_address_: string | undefined, |
28 | filter_created_at_: string | undefined, |
29 | filter_action_: string | undefined, |
30 | sort_by: string | undefined, |
31 | sort_order: string | undefined, |
32 | sort: string | undefined |
33 | ) { |
34 | const url = new URL( |
35 | `https://${auth.subdomain}.zendesk.com/api/v2/audit_logs` |
36 | ); |
37 | for (const [k, v] of [ |
38 | ["filter[source_type]", filter_source_type_], |
39 | ["filter[source_id]", filter_source_id_], |
40 | ["filter[actor_id]", filter_actor_id_], |
41 | ["filter[ip_address]", filter_ip_address_], |
42 | ["filter[created_at]", filter_created_at_], |
43 | ["filter[action]", filter_action_], |
44 | ["sort_by", sort_by], |
45 | ["sort_order", sort_order], |
46 | ["sort", sort], |
47 | ]) { |
48 | if (v !== undefined && v !== "") { |
49 | url.searchParams.append(k, v); |
50 | } |
51 | } |
52 | const response = await fetch(url, { |
53 | method: "GET", |
54 | headers: { |
55 | Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`), |
56 | }, |
57 | body: undefined, |
58 | }); |
59 | if (!response.ok) { |
60 | const text = await response.text(); |
61 | throw new Error(`${response.status} ${text}`); |
62 | } |
63 | return await response.json(); |
64 | } |
65 |
|