List Triggers

Lists all triggers for the current account.

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 Triggers
8
 * Lists all triggers for the current account.
9
 */
10
export async function main(
11
  auth: Zendesk,
12
  active: string | undefined,
13
  sort: string | undefined,
14
  sort_by: string | undefined,
15
  sort_order: string | undefined,
16
  category_id: string | undefined
17
) {
18
  const url = new URL(`https://${auth.subdomain}.zendesk.com/api/v2/triggers`);
19
  for (const [k, v] of [
20
    ["active", active],
21
    ["sort", sort],
22
    ["sort_by", sort_by],
23
    ["sort_order", sort_order],
24
    ["category_id", category_id],
25
  ]) {
26
    if (v !== undefined && v !== "") {
27
      url.searchParams.append(k, v);
28
    }
29
  }
30
  const response = await fetch(url, {
31
    method: "GET",
32
    headers: {
33
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
34
    },
35
    body: undefined,
36
  });
37
  if (!response.ok) {
38
    const text = await response.text();
39
    throw new Error(`${response.status} ${text}`);
40
  }
41
  return await response.json();
42
}
43