Bulk get groups

Returns a [paginated](#pagination) list of groups. **[Permissions](#permissions) required:** *Browse users and groups* [global permission](https://confluence.atlassian.com/x/x4dKLg).

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 groups
8
 * Returns a [paginated](#pagination) list of groups.
9

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