List Views By ID

#### Allowed For * Agents #### 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

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 Views By ID
8
 * #### Allowed For
9

10
* Agents
11

12
#### Sideloads
13

14
The following sideloads are supported:
15

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

21
 */
22
export async function main(
23
  auth: Zendesk,
24
  ids: string | undefined,
25
  active: string | undefined
26
) {
27
  const url = new URL(
28
    `https://${auth.subdomain}.zendesk.com/api/v2/views/show_many`
29
  );
30
  for (const [k, v] of [
31
    ["ids", ids],
32
    ["active", active],
33
  ]) {
34
    if (v !== undefined && v !== "") {
35
      url.searchParams.append(k, v);
36
    }
37
  }
38
  const response = await fetch(url, {
39
    method: "GET",
40
    headers: {
41
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
42
    },
43
    body: undefined,
44
  });
45
  if (!response.ok) {
46
    const text = await response.text();
47
    throw new Error(`${response.status} ${text}`);
48
  }
49
  return await response.json();
50
}
51