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

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

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