0

Get Dynamic Content Items by Name

by
Published Nov 7, 2023

Retrieve several dynamic content items by their identifier (the `name` in `{{dc.name}}`), with their variants.

Script zendesk Verified

The script

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

3
/**
4
 * Get Dynamic Content Items by Name
5
 * Retrieve several dynamic content items by their identifier (the `name` in `{{dc.name}}`), with their variants.
6
 */
7
export async function main(auth: RT.Zendesk, identifiers: string[]) {
8
  const url = new URL(
9
    `https://${auth.subdomain}.zendesk.com/api/v2/dynamic_content/items/show_many`
10
  )
11
  url.searchParams.append("identifiers", identifiers.join(","))
12

13
  const response = await fetch(url, {
14
    headers: {
15
      Authorization: auth.token
16
        ? `Bearer ${auth.token}`
17
        : `Basic ${btoa(`${auth.username}:${auth.password}`)}`,
18
      Accept: "application/json",
19
    },
20
  })
21

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

26
  return await response.json()
27
}
28

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 Many Items
    8
     * #### Stability
    9
    
    
    10
    * Development
    11
    
    
    12
    #### Allowed For
    13
    
    
    14
    * Admins, Agents
    15
    
    
    16
     */
    17
    export async function main(auth: Zendesk, identifiers: string | undefined) {
    18
      const url = new URL(
    19
        `https://${auth.subdomain}.zendesk.com/api/v2/dynamic_content/items/show_many`
    20
      );
    21
      for (const [k, v] of [["identifiers", identifiers]]) {
    22
        if (v !== undefined && v !== "") {
    23
          url.searchParams.append(k, v);
    24
        }
    25
      }
    26
      const response = await fetch(url, {
    27
        method: "GET",
    28
        headers: {
    29
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
    30
        },
    31
        body: undefined,
    32
      });
    33
      if (!response.ok) {
    34
        const text = await response.text();
    35
        throw new Error(`${response.status} ${text}`);
    36
      }
    37
      return await response.json();
    38
    }
    39