Get users from group

Returns a [paginated](#pagination) list of all users in a group. Note that users are ordered by username, however the username is not returned in the results due to privacy reasons. **[Permissions](#permissions) required:** *Administer Jira* [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
 * Get users from group
8
 * Returns a [paginated](#pagination) list of all users in a group.
9

10
Note that users are ordered by username, however the username is not returned in the results due to privacy reasons.
11

12
**[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).
13
 */
14
export async function main(
15
  auth: Jira,
16
  groupname: string | undefined,
17
  groupId: string | undefined,
18
  includeInactiveUsers: string | undefined,
19
  startAt: string | undefined,
20
  maxResults: string | undefined
21
) {
22
  const url = new URL(
23
    `https://${auth.domain}.atlassian.net/rest/api/2/group/member`
24
  );
25
  for (const [k, v] of [
26
    ["groupname", groupname],
27
    ["groupId", groupId],
28
    ["includeInactiveUsers", includeInactiveUsers],
29
    ["startAt", startAt],
30
    ["maxResults", maxResults],
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