0

List Dynamic Content Items

by
Published Nov 7, 2023

List the account's dynamic content items (reusable, localized text referenced as `{{dc.name}}` in macros, triggers and articles). Cursor-paged: pass `meta.after_cursor` as `cursor` while `meta.has_more` is true.

Script zendesk Verified

The script

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

3
/**
4
 * List Dynamic Content Items
5
 * List the account's dynamic content items (reusable, localized text referenced as `{{dc.name}}` in macros, triggers and articles). Cursor-paged: pass `meta.after_cursor` as `cursor` while `meta.has_more` is true.
6
 */
7
export async function main(
8
  auth: RT.Zendesk,
9
  sort:
10
    | "created_at"
11
    | "-created_at"
12
    | "updated_at"
13
    | "-updated_at"
14
    | "locale"
15
    | "-locale"
16
    | "active"
17
    | "-active"
18
    | "outdated"
19
    | "-outdated"
20
    | undefined,
21
  page_size: number | undefined,
22
  cursor: string | undefined
23
) {
24
  const url = new URL(
25
    `https://${auth.subdomain}.zendesk.com/api/v2/dynamic_content/items`
26
  )
27
  url.searchParams.append("page[size]", String(page_size || 100))
28
  if (sort) {
29
    url.searchParams.append("sort", sort)
30
  }
31
  if (cursor) {
32
    url.searchParams.append("page[after]", cursor)
33
  }
34

35
  const response = await fetch(url, {
36
    headers: {
37
      Authorization: auth.token
38
        ? `Bearer ${auth.token}`
39
        : `Basic ${btoa(`${auth.username}:${auth.password}`)}`,
40
      Accept: "application/json",
41
    },
42
  })
43

44
  if (!response.ok) {
45
    throw new Error(`${response.status} ${await response.text()}`)
46
  }
47

48
  return await response.json()
49
}
50

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
     * List Items
    8
     * Returns a list of all dynamic content items for your account if accessed as an admin or agents who have permission to manage dynamic content.
    9
    
    
    10
    #### Allowed For
    11
    
    
    12
    * Admins, Agents
    13
    
    
    14
     */
    15
    export async function main(auth: Zendesk) {
    16
      const url = new URL(
    17
        `https://${auth.subdomain}.zendesk.com/api/v2/dynamic_content/items`
    18
      );
    19
    
    
    20
      const response = await fetch(url, {
    21
        method: "GET",
    22
        headers: {
    23
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
    24
        },
    25
        body: undefined,
    26
      });
    27
      if (!response.ok) {
    28
        const text = await response.text();
    29
        throw new Error(`${response.status} ${text}`);
    30
      }
    31
      return await response.json();
    32
    }
    33