0

List Views

by
Published Nov 7, 2023

List the views the agent can use (shared and personal), optionally only the active or inactive ones. 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 7 days ago
1
//native
2

3
/**
4
 * List Views
5
 * List the views the agent can use (shared and personal), optionally only the active or inactive ones. 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
  active: "true" | "false" | undefined,
10
  page_size: number | undefined,
11
  cursor: string | undefined
12
) {
13
  const url = new URL(`https://${auth.subdomain}.zendesk.com/api/v2/views`)
14
  url.searchParams.append("page[size]", String(page_size || 100))
15
  if (active) {
16
    url.searchParams.append("active", active)
17
  }
18
  if (cursor) {
19
    url.searchParams.append("page[after]", cursor)
20
  }
21

22
  const response = await fetch(url, {
23
    headers: {
24
      Authorization: auth.token
25
        ? `Bearer ${auth.token}`
26
        : `Basic ${btoa(`${auth.username}:${auth.password}`)}`,
27
      Accept: "application/json",
28
    },
29
  })
30

31
  if (!response.ok) {
32
    throw new Error(`${response.status} ${await response.text()}`)
33
  }
34

35
  return await response.json()
36
}
37

Other submissions
  • Submitted by hugo697 Typescript (fetch-only)
    Created 534 days ago
    1
    type Zendesk = {
    2
      username: string;
    3
      password: string;
    4
      subdomain: string;
    5
    };
    6
    /**
    7
     * List Views
    8
     * Lists shared and personal views available to the current user.
    9
     */
    10
    export async function main(
    11
      auth: Zendesk,
    12
      access: string | undefined,
    13
      active: string | undefined,
    14
      group_id: string | undefined,
    15
      sort_by: string | undefined,
    16
      sort_order: string | undefined
    17
    ) {
    18
      const url = new URL(`https://${auth.subdomain}.zendesk.com/api/v2/views`);
    19
      for (const [k, v] of [
    20
        ["access", access],
    21
        ["active", active],
    22
        ["group_id", group_id],
    23
        ["sort_by", sort_by],
    24
        ["sort_order", sort_order],
    25
      ]) {
    26
        if (v !== undefined && v !== "") {
    27
          url.searchParams.append(k, v);
    28
        }
    29
      }
    30
      const response = await fetch(url, {
    31
        method: "GET",
    32
        headers: {
    33
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
    34
        },
    35
        body: undefined,
    36
      });
    37
      if (!response.ok) {
    38
        const text = await response.text();
    39
        throw new Error(`${response.status} ${text}`);
    40
      }
    41
      return await response.json();
    42
    }
    43