0

Associate security scheme to project

Published Nov 2, 2023

Associates an issue security scheme with a project and remaps security levels of issues to the new levels, if provided. This operation is [asynchronous](#async). Follow the `location` link in the response to determine the status of the task and use [Get task](#api-rest-api-2-task-taskId-get) to obtain subsequent updates. **[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).

Script jira
  • Submitted by hugo697 Typescript (fetch-only)
    Created 565 days ago
    1
    type Jira = {
    2
      username: string;
    3
      password: string;
    4
      domain: string;
    5
    };
    6
    /**
    7
     * Associate security scheme to project
    8
     * Associates an issue security scheme with a project and remaps security levels of issues to the new levels, if provided.
    9
    
    
    10
    This operation is [asynchronous](#async). Follow the `location` link in the response to determine the status of the task and use [Get task](#api-rest-api-2-task-taskId-get) to obtain subsequent updates.
    11
    
    
    12
    **[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).
    13
     */
    14
    export async function main(
    15
      auth: Jira,
    16
      body: {
    17
        oldToNewSecurityLevelMappings?: {
    18
          newLevelId: string;
    19
          oldLevelId: string;
    20
        }[];
    21
        projectId: string;
    22
        schemeId: string;
    23
      }
    24
    ) {
    25
      const url = new URL(
    26
        `https://${auth.domain}.atlassian.net/rest/api/2/issuesecurityschemes/project`
    27
      );
    28
    
    
    29
      const response = await fetch(url, {
    30
        method: "PUT",
    31
        headers: {
    32
          "Content-Type": "application/json",
    33
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
    34
        },
    35
        body: JSON.stringify(body),
    36
      });
    37
      if (!response.ok) {
    38
        const text = await response.text();
    39
        throw new Error(`${response.status} ${text}`);
    40
      }
    41
      return await response.text();
    42
    }
    43