0

Add issue types to issue type scheme

by
Published Nov 2, 2023

Adds issue types to an issue type scheme. The added issue types are appended to the issue types list. If any of the issue types exist in the issue type scheme, the operation fails and no issue types are added. **[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).

Script jira Verified

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 416 days ago
1
type Jira = {
2
  username: string;
3
  password: string;
4
  domain: string;
5
};
6
/**
7
 * Add issue types to issue type scheme
8
 * Adds issue types to an issue type scheme.
9

10
The added issue types are appended to the issue types list.
11

12
If any of the issue types exist in the issue type scheme, the operation fails and no issue types are added.
13

14
**[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).
15
 */
16
export async function main(
17
  auth: Jira,
18
  issueTypeSchemeId: string,
19
  body: { issueTypeIds: string[] }
20
) {
21
  const url = new URL(
22
    `https://${auth.domain}.atlassian.net/rest/api/2/issuetypescheme/${issueTypeSchemeId}/issuetype`
23
  );
24

25
  const response = await fetch(url, {
26
    method: "PUT",
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