0

Get Dynamic Content Item

by
Published Nov 7, 2023

Retrieve a dynamic content item and its variants (one per locale).

Script zendesk Verified

The script

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

3
/**
4
 * Get Dynamic Content Item
5
 * Retrieve a dynamic content item and its variants (one per locale).
6
 */
7
export async function main(auth: RT.Zendesk, item_id: number) {
8
  const response = await fetch(
9
    `https://${auth.subdomain}.zendesk.com/api/v2/dynamic_content/items/${item_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 Item
    8
     * #### Allowed For
    9
    
    
    10
    * Admins, Agents
    11
    
    
    12
     */
    13
    export async function main(auth: Zendesk, dynamic_content_item_id: string) {
    14
      const url = new URL(
    15
        `https://${auth.subdomain}.zendesk.com/api/v2/dynamic_content/items/${dynamic_content_item_id}`
    16
      );
    17
    
    
    18
      const response = await fetch(url, {
    19
        method: "GET",
    20
        headers: {
    21
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
    22
        },
    23
        body: undefined,
    24
      });
    25
      if (!response.ok) {
    26
        const text = await response.text();
    27
        throw new Error(`${response.status} ${text}`);
    28
      }
    29
      return await response.json();
    30
    }
    31