Find users with browse permission

Returns a list of users who fulfill these criteria: * their user attributes match a search 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 users with browse permission
8
 * Returns a list of users who fulfill these criteria:
9

10
 *  their user attributes match a search string.
11
 */
12
export async function main(
13
  auth: Jira,
14
  query: string | undefined,
15
  username: string | undefined,
16
  accountId: string | undefined,
17
  issueKey: string | undefined,
18
  projectKey: 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/user/viewissue/search`
24
  );
25
  for (const [k, v] of [
26
    ["query", query],
27
    ["username", username],
28
    ["accountId", accountId],
29
    ["issueKey", issueKey],
30
    ["projectKey", projectKey],
31
    ["startAt", startAt],
32
    ["maxResults", maxResults],
33
  ]) {
34
    if (v !== undefined && v !== "") {
35
      url.searchParams.append(k, v);
36
    }
37
  }
38
  const response = await fetch(url, {
39
    method: "GET",
40
    headers: {
41
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
42
    },
43
    body: undefined,
44
  });
45
  if (!response.ok) {
46
    const text = await response.text();
47
    throw new Error(`${response.status} ${text}`);
48
  }
49
  return await response.json();
50
}
51