0

Add actors to project role

by
Published Nov 2, 2023

Adds actors to a project role for the project. To replace all actors for the project, use [Set actors for project role](#api-rest-api-2-project-projectIdOrKey-role-id-put). 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
  • Submitted by hugo697 Typescript (fetch-only)
    Created 525 days ago
    1
    type Jira = {
    2
      username: string;
    3
      password: string;
    4
      domain: string;
    5
    };
    6
    /**
    7
     * Add actors to project role
    8
     * Adds actors to a project role for the project.
    9
    
    
    10
    To replace all actors for the project, use [Set actors for project role](#api-rest-api-2-project-projectIdOrKey-role-id-put).
    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
      body: { group?: string[]; groupId?: string[]; user?: string[] }
    21
    ) {
    22
      const url = new URL(
    23
        `https://${auth.domain}.atlassian.net/rest/api/2/project/${projectIdOrKey}/role/${id}`
    24
      );
    25
    
    
    26
      const response = await fetch(url, {
    27
        method: "POST",
    28
        headers: {
    29
          "Content-Type": "application/json",
    30
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
    31
        },
    32
        body: JSON.stringify(body),
    33
      });
    34
      if (!response.ok) {
    35
        const text = await response.text();
    36
        throw new Error(`${response.status} ${text}`);
    37
      }
    38
      return await response.json();
    39
    }
    40