0

Set workflow for issue type in draft workflow scheme

Published Nov 2, 2023

Sets the workflow for an issue type in a workflow scheme's draft. **[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
     * Set workflow for issue type in draft workflow scheme
    8
     * Sets the workflow for an issue type in a workflow scheme's draft.
    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
      id: string,
    15
      issueType: string,
    16
      body: { issueType?: string; updateDraftIfNeeded?: boolean; workflow?: string }
    17
    ) {
    18
      const url = new URL(
    19
        `https://${auth.domain}.atlassian.net/rest/api/2/workflowscheme/${id}/draft/issuetype/${issueType}`
    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