Update Macro

#### Allowed For * Agents

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 Macro
8
 * #### Allowed For
9
* Agents
10

11
 */
12
export async function main(
13
  auth: Zendesk,
14
  macro_id: string,
15
  body: {
16
    macro?: {
17
      actions?: { field?: string; value?: string; [k: string]: unknown }[];
18
      active?: string;
19
      description?: string;
20
      restriction?: {
21
        id?: string;
22
        ids?: string[];
23
        reprehenderit_aef?: number;
24
        type?: string;
25
        [k: string]: unknown;
26
      };
27
      title?: string;
28
      [k: string]: unknown;
29
    };
30
    [k: string]: unknown;
31
  }
32
) {
33
  const url = new URL(
34
    `https://${auth.subdomain}.zendesk.com/api/v2/macros/${macro_id}`
35
  );
36

37
  const response = await fetch(url, {
38
    method: "PUT",
39
    headers: {
40
      "Content-Type": "application/json",
41
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
42
    },
43
    body: JSON.stringify(body),
44
  });
45
  if (!response.ok) {
46
    const text = await response.text();
47
    throw new Error(`${response.status} ${text}`);
48
  }
49
  return await response.json();
50
}
51