Update Trigger

#### Allowed For * Agents #### Note Updating a condition or action updates both the conditions and actions arrays, clearing all existing values of both arrays. Include all your conditions and actions when updating any condition or action.

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 Trigger
8
 * #### Allowed For
9

10
* Agents
11

12
#### Note
13

14
Updating a condition or action updates both the conditions and actions arrays,
15
clearing all existing values of both arrays. Include all your conditions
16
and actions when updating any condition or action.
17

18
 */
19
export async function main(
20
  auth: Zendesk,
21
  trigger_id: string,
22
  body: {
23
    trigger?: { value?: string; [k: string]: unknown };
24
    [k: string]: unknown;
25
  }
26
) {
27
  const url = new URL(
28
    `https://${auth.subdomain}.zendesk.com/api/v2/triggers/${trigger_id}`
29
  );
30

31
  const response = await fetch(url, {
32
    method: "PUT",
33
    headers: {
34
      "Content-Type": "application/json",
35
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
36
    },
37
    body: JSON.stringify(body),
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