List Active Macros

Lists all active shared and personal macros available to the current user. #### 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
 * List Active Macros
8
 * Lists all active shared and personal macros available to the current user.
9

10
#### Allowed For
11
* Agents
12

13
 */
14
export async function main(
15
  auth: Zendesk,
16
  include: string | undefined,
17
  access: string | undefined,
18
  category: string | undefined,
19
  group_id: string | undefined,
20
  sort_by: string | undefined,
21
  sort_order: string | undefined
22
) {
23
  const url = new URL(
24
    `https://${auth.subdomain}.zendesk.com/api/v2/macros/active`
25
  );
26
  for (const [k, v] of [
27
    ["include", include],
28
    ["access", access],
29
    ["category", category],
30
    ["group_id", group_id],
31
    ["sort_by", sort_by],
32
    ["sort_order", sort_order],
33
  ]) {
34
    if (v !== undefined && v !== "") {
35
      url.searchParams.append(k, v);
36
    }
37
  }
38
  const response = await fetch(url, {
39
    method: "GET",
40
    headers: {
41
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
42
    },
43
    body: undefined,
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