Find groups

Returns a list of groups whose names contain a query string.

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
 * Find groups
8
 * Returns a list of groups whose names contain a query string.
9
 */
10
export async function main(
11
  auth: Jira,
12
  accountId: string | undefined,
13
  query: string | undefined,
14
  exclude: string | undefined,
15
  excludeId: string | undefined,
16
  maxResults: string | undefined,
17
  caseInsensitive: string | undefined,
18
  userName: string | undefined
19
) {
20
  const url = new URL(
21
    `https://${auth.domain}.atlassian.net/rest/api/2/groups/picker`
22
  );
23
  for (const [k, v] of [
24
    ["accountId", accountId],
25
    ["query", query],
26
    ["exclude", exclude],
27
    ["excludeId", excludeId],
28
    ["maxResults", maxResults],
29
    ["caseInsensitive", caseInsensitive],
30
    ["userName", userName],
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