0

Create issue type

Published Nov 2, 2023

Creates an issue type and adds it to the default issue type scheme. **[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
     * Create issue type
    8
     * Creates an issue type and adds it to the default issue type scheme.
    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
      body: {
    15
        description?: string;
    16
        hierarchyLevel?: number;
    17
        name: string;
    18
        type?: "subtask" | "standard";
    19
      }
    20
    ) {
    21
      const url = new URL(
    22
        `https://${auth.domain}.atlassian.net/rest/api/2/issuetype`
    23
      );
    24
    
    
    25
      const response = await fetch(url, {
    26
        method: "POST",
    27
        headers: {
    28
          "Content-Type": "application/json",
    29
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
    30
        },
    31
        body: JSON.stringify(body),
    32
      });
    33
      if (!response.ok) {
    34
        const text = await response.text();
    35
        throw new Error(`${response.status} ${text}`);
    36
      }
    37
      return await response.json();
    38
    }
    39