Create permission grant

Creates a permission grant in a permission scheme. **[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
 * Create permission grant
8
 * Creates a permission grant in a permission scheme.
9

10
**[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).
11
 */
12
export async function main(
13
  auth: Jira,
14
  schemeId: string,
15
  expand: string | undefined,
16
  body: {
17
    holder?: {
18
      expand?: string;
19
      parameter?: string;
20
      type: string;
21
      value?: string;
22
    };
23
    id?: number;
24
    permission?: string;
25
    self?: string;
26
    [k: string]: unknown;
27
  }
28
) {
29
  const url = new URL(
30
    `https://${auth.domain}.atlassian.net/rest/api/2/permissionscheme/${schemeId}/permission`
31
  );
32
  for (const [k, v] of [["expand", expand]]) {
33
    if (v !== undefined && v !== "") {
34
      url.searchParams.append(k, v);
35
    }
36
  }
37
  const response = await fetch(url, {
38
    method: "POST",
39
    headers: {
40
      "Content-Type": "application/json",
41
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
42
    },
43
    body: JSON.stringify(body),
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