0

Get Macro

by
Published Nov 7, 2023

Retrieve a macro, with the actions it applies.

Script zendesk Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 2 hours ago
1
//native
2

3
/**
4
 * Get Macro
5
 * Retrieve a macro, with the actions it applies.
6
 */
7
export async function main(auth: RT.Zendesk, macro_id: number) {
8
  const response = await fetch(
9
    `https://${auth.subdomain}.zendesk.com/api/v2/macros/${macro_id}`,
10
    {
11
      headers: {
12
        Authorization: auth.token
13
          ? `Bearer ${auth.token}`
14
          : `Basic ${btoa(`${auth.username}:${auth.password}`)}`,
15
        Accept: "application/json",
16
      },
17
    }
18
  )
19

20
  if (!response.ok) {
21
    throw new Error(`${response.status} ${await response.text()}`)
22
  }
23

24
  return await response.json()
25
}
26

Other submissions
  • Submitted by hugo697 Typescript (fetch-only)
    Created 528 days ago
    1
    type Zendesk = {
    2
      username: string;
    3
      password: string;
    4
      subdomain: string;
    5
    };
    6
    /**
    7
     * Show Macro
    8
     * #### Allowed For
    9
    * Agents
    10
    
    
    11
     */
    12
    export async function main(auth: Zendesk, macro_id: string) {
    13
      const url = new URL(
    14
        `https://${auth.subdomain}.zendesk.com/api/v2/macros/${macro_id}`
    15
      );
    16
    
    
    17
      const response = await fetch(url, {
    18
        method: "GET",
    19
        headers: {
    20
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
    21
        },
    22
        body: undefined,
    23
      });
    24
      if (!response.ok) {
    25
        const text = await response.text();
    26
        throw new Error(`${response.status} ${text}`);
    27
      }
    28
      return await response.json();
    29
    }
    30