1 | type Zendesk = { |
2 | username: string; |
3 | password: string; |
4 | subdomain: string; |
5 | }; |
6 | |
7 | * List Trigger Categories |
8 | * Returns all the trigger categories in the account. |
9 | */ |
10 | export async function main( |
11 | auth: Zendesk, |
12 | page_after_: string | undefined, |
13 | page_before_: string | undefined, |
14 | page_size_: string | undefined, |
15 | sort: string | undefined, |
16 | include: string | undefined |
17 | ) { |
18 | const url = new URL( |
19 | `https://${auth.subdomain}.zendesk.com/api/v2/trigger_categories` |
20 | ); |
21 | for (const [k, v] of [ |
22 | ["page[after]", page_after_], |
23 | ["page[before]", page_before_], |
24 | ["page[size]", page_size_], |
25 | ["sort", sort], |
26 | ["include", include], |
27 | ]) { |
28 | if (v !== undefined && v !== "") { |
29 | url.searchParams.append(k, v); |
30 | } |
31 | } |
32 | const response = await fetch(url, { |
33 | method: "GET", |
34 | headers: { |
35 | Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`), |
36 | }, |
37 | body: undefined, |
38 | }); |
39 | if (!response.ok) { |
40 | const text = await response.text(); |
41 | throw new Error(`${response.status} ${text}`); |
42 | } |
43 | return await response.json(); |
44 | } |
45 |
|