Show Macro Replica

Returns an unpersisted macro representation derived from a ticket or macro. The endpoint takes one of the following query parameters: `macro_id` or `ticket_id`. If you include both, `macro_id` is used. #### 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
 * Show Macro Replica
8
 * Returns an unpersisted macro representation derived from a ticket or macro.
9

10
The endpoint takes one of the following query parameters: `macro_id` or `ticket_id`. If you include both, `macro_id` is used.
11

12
#### Allowed For
13
* Agents
14

15
 */
16
export async function main(
17
  auth: Zendesk,
18
  macro_id: string | undefined,
19
  ticket_id: string | undefined
20
) {
21
  const url = new URL(
22
    `https://${auth.subdomain}.zendesk.com/api/v2/macros/new`
23
  );
24
  for (const [k, v] of [
25
    ["macro_id", macro_id],
26
    ["ticket_id", ticket_id],
27
  ]) {
28
    if (v !== undefined && v !== "") {
29
      url.searchParams.append(k, v);
30
    }
31
  }
32
  const response = await fetch(url, {
33
    method: "GET",
34
    headers: {
35
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
36
    },
37
    body: undefined,
38
  });
39
  if (!response.ok) {
40
    const text = await response.text();
41
    throw new Error(`${response.status} ${text}`);
42
  }
43
  return await response.json();
44
}
45