Get permission scheme
One script reply has been approved by the moderators Verified

Returns a permission scheme.

Permissions required: Permission to access Jira.

Created by hugo697 879 days ago
Submitted by hugo697 Typescript (fetch-only)
Verified 327 days ago
1
type Jira = {
2
  username: string;
3
  password: string;
4
  domain: string;
5
};
6
/**
7
 * Get permission scheme
8
 * Returns a permission scheme.
9

10
**[Permissions](#permissions) required:** Permission to access Jira.
11
 */
12
export async function main(
13
  auth: Jira,
14
  schemeId: string,
15
  expand: string | undefined
16
) {
17
  const url = new URL(
18
    `https://${auth.domain}.atlassian.net/rest/api/2/permissionscheme/${schemeId}`
19
  );
20
  for (const [k, v] of [["expand", expand]]) {
21
    if (v !== undefined && v !== "") {
22
      url.searchParams.append(k, v);
23
    }
24
  }
25
  const response = await fetch(url, {
26
    method: "GET",
27
    headers: {
28
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
29
    },
30
    body: undefined,
31
  });
32
  if (!response.ok) {
33
    const text = await response.text();
34
    throw new Error(`${response.status} ${text}`);
35
  }
36
  return await response.json();
37
}
38