Change order of issue types

Changes the order of issue types in an issue type scheme. The request body parameters must meet the following requirements: * all of the issue types must belong to the issue type scheme. * either `after` or `position` must be provided. * the issue type in `after` must not be in the issue type list. **[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
 * Change order of issue types
8
 * Changes the order of issue types in an issue type scheme.
9

10
The request body parameters must meet the following requirements:
11

12
 *  all of the issue types must belong to the issue type scheme.
13
 *  either `after` or `position` must be provided.
14
 *  the issue type in `after` must not be in the issue type list.
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
  body: { after?: string; issueTypeIds: string[]; position?: "First" | "Last" }
22
) {
23
  const url = new URL(
24
    `https://${auth.domain}.atlassian.net/rest/api/2/issuetypescheme/${issueTypeSchemeId}/issuetype/move`
25
  );
26

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