Bulk get users

Returns a [paginated](#pagination) list of the users specified by one or more account IDs. **[Permissions](#permissions) required:** Permission to access Jira.

Script jira Verified

by hugo697 ยท 11/2/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 396 days ago
1
type Jira = {
2
  username: string;
3
  password: string;
4
  domain: string;
5
};
6
/**
7
 * Bulk get users
8
 * Returns a [paginated](#pagination) list of the users specified by one or more account IDs.
9

10
**[Permissions](#permissions) required:** Permission to access Jira.
11
 */
12
export async function main(
13
  auth: Jira,
14
  startAt: string | undefined,
15
  maxResults: string | undefined,
16
  username: string | undefined,
17
  key: string | undefined,
18
  accountId: string | undefined
19
) {
20
  const url = new URL(
21
    `https://${auth.domain}.atlassian.net/rest/api/2/user/bulk`
22
  );
23
  for (const [k, v] of [
24
    ["startAt", startAt],
25
    ["maxResults", maxResults],
26
    ["username", username],
27
    ["key", key],
28
    ["accountId", accountId],
29
  ]) {
30
    if (v !== undefined && v !== "") {
31
      url.searchParams.append(k, v);
32
    }
33
  }
34
  const response = await fetch(url, {
35
    method: "GET",
36
    headers: {
37
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
38
    },
39
    body: undefined,
40
  });
41
  if (!response.ok) {
42
    const text = await response.text();
43
    throw new Error(`${response.status} ${text}`);
44
  }
45
  return await response.json();
46
}
47