Create issue type
One script reply has been approved by the moderators Verified

Creates an issue type and adds it to the default issue type scheme.

Permissions required: Administer Jira global permission.

Created by hugo697 879 days ago
Submitted by hugo697 Typescript (fetch-only)
Verified 327 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