Remove issue type from issue type scheme

Removes an issue type from an issue type scheme. This operation cannot remove: * any issue type used by issues. * any issue types from the default issue type scheme. * the last standard issue type from an issue type scheme. **[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).

Script jira Verified

by hugo697 ยท 11/2/2023

The script

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

10
This operation cannot remove:
11

12
 *  any issue type used by issues.
13
 *  any issue types from the default issue type scheme.
14
 *  the last standard issue type from an issue type scheme.
15

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

27
  const response = await fetch(url, {
28
    method: "DELETE",
29
    headers: {
30
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
31
    },
32
    body: undefined,
33
  });
34
  if (!response.ok) {
35
    const text = await response.text();
36
    throw new Error(`${response.status} ${text}`);
37
  }
38
  return await response.json();
39
}
40