Show Many Users

Accepts a comma-separated list of up to 100 user ids or external ids. #### 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
 * Show Many Users
8
 * Accepts a comma-separated list of up to 100 user ids or external ids.
9

10
#### Allowed For:
11

12
* Agents
13

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