Update Many Macros

Updates the provided macros with the specified changes. #### 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 Many Macros
8
 * Updates the provided macros with the specified changes.
9

10
#### Allowed For
11
* Agents
12

13
 */
14
export async function main(
15
  auth: Zendesk,
16
  body: {
17
    macros?: {
18
      active?: string;
19
      id?: string;
20
      position?: string;
21
      [k: string]: unknown;
22
    }[];
23
    [k: string]: unknown;
24
  }
25
) {
26
  const url = new URL(
27
    `https://${auth.subdomain}.zendesk.com/api/v2/macros/update_many`
28
  );
29

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