Search Views

#### Pagination * Offset pagination only See Using Offset Pagination. #### Allowed For * Agents #### Sideloads The following sideloads are supported. For more information, see Side-loading. | Name | Will sideload | ---------------- | ------------- | app_installation | The app installation that requires each view, if present | permissions | The permissions for each view

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
 * Search Views
8
 * #### Pagination
9

10
* Offset pagination only
11

12
See Using Offset Pagination.
13

14
#### Allowed For
15

16
* Agents
17

18
#### Sideloads
19

20
The following sideloads are supported. For more information, see Side-loading.
21

22
| Name             | Will sideload
23
| ---------------- | -------------
24
| app_installation | The app installation that requires each view, if present
25
| permissions      | The permissions for each view
26

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