0

Assign workflow scheme to project

by
Published Nov 2, 2023

Assigns a workflow scheme to a project. This operation is performed only when there are no issues in the project. Workflow schemes can only be assigned to classic projects. **[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).

Script jira
  • Submitted by hugo697 Typescript (fetch-only)
    Created 527 days ago
    1
    type Jira = {
    2
      username: string;
    3
      password: string;
    4
      domain: string;
    5
    };
    6
    /**
    7
     * Assign workflow scheme to project
    8
     * Assigns a workflow scheme to a project. This operation is performed only when there are no issues in the project.
    9
    
    
    10
    Workflow schemes can only be assigned to classic projects.
    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: { projectId: string; workflowSchemeId?: string }
    17
    ) {
    18
      const url = new URL(
    19
        `https://${auth.domain}.atlassian.net/rest/api/2/workflowscheme/project`
    20
      );
    21
    
    
    22
      const response = await fetch(url, {
    23
        method: "PUT",
    24
        headers: {
    25
          "Content-Type": "application/json",
    26
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
    27
        },
    28
        body: JSON.stringify(body),
    29
      });
    30
      if (!response.ok) {
    31
        const text = await response.text();
    32
        throw new Error(`${response.status} ${text}`);
    33
      }
    34
      return await response.json();
    35
    }
    36