List Macros

Lists all shared and personal macros available to the current user. For admins, the API returns all macros for the account, including the personal macros of agents and other admins. #### Pagination - Cursor pagination (recommended) - Offset pagination See Pagination. Returns a maximum of 100 records per page. #### 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 Macros
8
 * Lists all shared and personal macros available to the current user. For admins, the API returns all macros for the account, including the personal macros of agents and other admins.
9

10
#### Pagination
11

12
- Cursor pagination (recommended)
13
- Offset pagination
14

15
See Pagination.
16

17
Returns a maximum of 100 records per page.
18

19
#### Allowed For
20
* Agents
21

22
 */
23
export async function main(
24
  auth: Zendesk,
25
  include: string | undefined,
26
  access: string | undefined,
27
  active: string | undefined,
28
  category: string | undefined,
29
  group_id: string | undefined,
30
  only_viewable: string | undefined,
31
  sort_by: string | undefined,
32
  sort_order: string | undefined
33
) {
34
  const url = new URL(`https://${auth.subdomain}.zendesk.com/api/v2/macros`);
35
  for (const [k, v] of [
36
    ["include", include],
37
    ["access", access],
38
    ["active", active],
39
    ["category", category],
40
    ["group_id", group_id],
41
    ["only_viewable", only_viewable],
42
    ["sort_by", sort_by],
43
    ["sort_order", sort_order],
44
  ]) {
45
    if (v !== undefined && v !== "") {
46
      url.searchParams.append(k, v);
47
    }
48
  }
49
  const response = await fetch(url, {
50
    method: "GET",
51
    headers: {
52
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
53
    },
54
    body: undefined,
55
  });
56
  if (!response.ok) {
57
    const text = await response.text();
58
    throw new Error(`${response.status} ${text}`);
59
  }
60
  return await response.json();
61
}
62