Update Many Triggers

Updates the position or the active status of multiple triggers.

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
 * Update Many Triggers
8
 * Updates the position or the active status of multiple triggers.
9
 */
10
export async function main(
11
  auth: Zendesk,
12
  body: {
13
    triggers?: {
14
      active?: string;
15
      category_id?: string;
16
      id?: string;
17
      position?: string;
18
      [k: string]: unknown;
19
    }[];
20
    [k: string]: unknown;
21
  }
22
) {
23
  const url = new URL(
24
    `https://${auth.subdomain}.zendesk.com/api/v2/triggers/update_many`
25
  );
26

27
  const response = await fetch(url, {
28
    method: "PUT",
29
    headers: {
30
      "Content-Type": "application/json",
31
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
32
    },
33
    body: JSON.stringify(body),
34
  });
35
  if (!response.ok) {
36
    const text = await response.text();
37
    throw new Error(`${response.status} ${text}`);
38
  }
39
  return await response.json();
40
}
41