Find users assignable to issues

Returns a list of users that can be assigned to an issue.

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 assignable to issues
8
 * Returns a list of users that can be assigned to an issue.
9
 */
10
export async function main(
11
  auth: Jira,
12
  query: string | undefined,
13
  sessionId: string | undefined,
14
  username: string | undefined,
15
  accountId: string | undefined,
16
  project: string | undefined,
17
  issueKey: string | undefined,
18
  startAt: string | undefined,
19
  maxResults: string | undefined,
20
  actionDescriptorId: string | undefined,
21
  recommend: string | undefined
22
) {
23
  const url = new URL(
24
    `https://${auth.domain}.atlassian.net/rest/api/2/user/assignable/search`
25
  );
26
  for (const [k, v] of [
27
    ["query", query],
28
    ["sessionId", sessionId],
29
    ["username", username],
30
    ["accountId", accountId],
31
    ["project", project],
32
    ["issueKey", issueKey],
33
    ["startAt", startAt],
34
    ["maxResults", maxResults],
35
    ["actionDescriptorId", actionDescriptorId],
36
    ["recommend", recommend],
37
  ]) {
38
    if (v !== undefined && v !== "") {
39
      url.searchParams.append(k, v);
40
    }
41
  }
42
  const response = await fetch(url, {
43
    method: "GET",
44
    headers: {
45
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
46
    },
47
    body: undefined,
48
  });
49
  if (!response.ok) {
50
    const text = await response.text();
51
    throw new Error(`${response.status} ${text}`);
52
  }
53
  return await response.json();
54
}
55