List Active Views

Lists active shared and personal views available to the current user. #### Sideloads The following sideloads are supported: | Name | Will sideload | ---------------- | ------------- | app_installation | The app installation that requires each view, if present | permissions | The permissions for each view #### Pagination - Offset pagination See Pagination. Returns a maximum of 100 records per page. #### Allowed For * Agents

Script zendesk Verified

by hugo697 ยท 11/7/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 377 days ago
1
type Zendesk = {
2
  username: string;
3
  password: string;
4
  subdomain: string;
5
};
6
/**
7
 * List Active Views
8
 * Lists active shared and personal views available to the current user.
9

10
#### Sideloads
11

12
The following sideloads are supported:
13

14
| Name             | Will sideload
15
| ---------------- | -------------
16
| app_installation | The app installation that requires each view, if present
17
| permissions      | The permissions for each view
18

19
#### Pagination
20

21
- Offset pagination
22

23
See Pagination.
24

25
Returns a maximum of 100 records per page.
26

27
#### Allowed For
28

29
* Agents
30

31
 */
32
export async function main(
33
  auth: Zendesk,
34
  access: string | undefined,
35
  group_id: string | undefined,
36
  sort_by: string | undefined,
37
  sort_order: string | undefined
38
) {
39
  const url = new URL(
40
    `https://${auth.subdomain}.zendesk.com/api/v2/views/active`
41
  );
42
  for (const [k, v] of [
43
    ["access", access],
44
    ["group_id", group_id],
45
    ["sort_by", sort_by],
46
    ["sort_order", sort_order],
47
  ]) {
48
    if (v !== undefined && v !== "") {
49
      url.searchParams.append(k, v);
50
    }
51
  }
52
  const response = await fetch(url, {
53
    method: "GET",
54
    headers: {
55
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
56
    },
57
    body: undefined,
58
  });
59
  if (!response.ok) {
60
    const text = await response.text();
61
    throw new Error(`${response.status} ${text}`);
62
  }
63
  return await response.json();
64
}
65