Search Automations

#### Pagination * Offset pagination only See Using Offset Pagination.

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
 * Search Automations
8
 * #### Pagination
9

10
* Offset pagination only
11

12
See Using Offset Pagination.
13
 */
14
export async function main(
15
  auth: Zendesk,
16
  query: string | undefined,
17
  active: string | undefined,
18
  sort_by: string | undefined,
19
  sort_order: string | undefined,
20
  include: string | undefined
21
) {
22
  const url = new URL(
23
    `https://${auth.subdomain}.zendesk.com/api/v2/automations/search`
24
  );
25
  for (const [k, v] of [
26
    ["query", query],
27
    ["active", active],
28
    ["sort_by", sort_by],
29
    ["sort_order", sort_order],
30
    ["include", include],
31
  ]) {
32
    if (v !== undefined && v !== "") {
33
      url.searchParams.append(k, v);
34
    }
35
  }
36
  const response = await fetch(url, {
37
    method: "GET",
38
    headers: {
39
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
40
    },
41
    body: undefined,
42
  });
43
  if (!response.ok) {
44
    const text = await response.text();
45
    throw new Error(`${response.status} ${text}`);
46
  }
47
  return await response.json();
48
}
49