1 | type Zendesk = { |
2 | username: string; |
3 | password: string; |
4 | subdomain: string; |
5 | }; |
6 | |
7 | * List Custom Object Records |
8 | * Lists all undeleted custom object records for the specified object |
9 |
|
10 | #### Pagination |
11 |
|
12 | * Cursor pagination only. |
13 | #### Allowed For |
14 | * Agents |
15 | */ |
16 | export async function main( |
17 | auth: Zendesk, |
18 | custom_object_key: string, |
19 | filter_ids_: string | undefined, |
20 | filter_external_ids_: string | undefined, |
21 | sort: string | undefined, |
22 | page_before_: string | undefined, |
23 | page_after_: string | undefined, |
24 | page_size_: string | undefined |
25 | ) { |
26 | const url = new URL( |
27 | `https://${auth.subdomain}.zendesk.com/api/v2/custom_objects/${custom_object_key}/records` |
28 | ); |
29 | for (const [k, v] of [ |
30 | ["filter[ids]", filter_ids_], |
31 | ["filter[external_ids]", filter_external_ids_], |
32 | ["sort", sort], |
33 | ["page[before]", page_before_], |
34 | ["page[after]", page_after_], |
35 | ["page[size]", page_size_], |
36 | ]) { |
37 | if (v !== undefined && v !== "") { |
38 | url.searchParams.append(k, v); |
39 | } |
40 | } |
41 | const response = await fetch(url, { |
42 | method: "GET", |
43 | headers: { |
44 | Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`), |
45 | }, |
46 | body: undefined, |
47 | }); |
48 | if (!response.ok) { |
49 | const text = await response.text(); |
50 | throw new Error(`${response.status} ${text}`); |
51 | } |
52 | return await response.json(); |
53 | } |
54 |
|