Update Trigger Category

Updates the trigger category with the specified ID.

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 Category
8
 * Updates the trigger category with the specified ID.
9
 */
10
export async function main(
11
  auth: Zendesk,
12
  trigger_category_id: string,
13
  body: {
14
    trigger_category?: {
15
      name?: string;
16
      position?: string;
17
      [k: string]: unknown;
18
    };
19
    [k: string]: unknown;
20
  }
21
) {
22
  const url = new URL(
23
    `https://${auth.subdomain}.zendesk.com/api/v2/trigger_categories/${trigger_category_id}`
24
  );
25

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