Delete actors from project role

Deletes actors from a project role for the project. To remove default actors from the project role, use [Delete default actors from project role](#api-rest-api-2-role-id-actors-delete). This operation can be accessed anonymously. **[Permissions](#permissions) required:** *Administer Projects* [project permission](https://confluence.atlassian.com/x/yodKLg) for the project or *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
 * Delete actors from project role
8
 * Deletes actors from a project role for the project.
9

10
To remove default actors from the project role, use [Delete default actors from project role](#api-rest-api-2-role-id-actors-delete).
11

12
This operation can be accessed anonymously.
13

14
**[Permissions](#permissions) required:** *Administer Projects* [project permission](https://confluence.atlassian.com/x/yodKLg) for the project or *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).
15
 */
16
export async function main(
17
  auth: Jira,
18
  projectIdOrKey: string,
19
  id: string,
20
  user: string | undefined,
21
  group: string | undefined,
22
  groupId: string | undefined
23
) {
24
  const url = new URL(
25
    `https://${auth.domain}.atlassian.net/rest/api/2/project/${projectIdOrKey}/role/${id}`
26
  );
27
  for (const [k, v] of [
28
    ["user", user],
29
    ["group", group],
30
    ["groupId", groupId],
31
  ]) {
32
    if (v !== undefined && v !== "") {
33
      url.searchParams.append(k, v);
34
    }
35
  }
36
  const response = await fetch(url, {
37
    method: "DELETE",
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.text();
48
}
49