Bulk update statuses

Updates statuses by ID. **[Permissions](#permissions) required:** * *Administer projects* [project permission.](https://confluence.atlassian.com/x/yodKLg) * *Administer Jira* [project permission.](https://confluence.atlassian.com/x/yodKLg)

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
 * Bulk update statuses
8
 * Updates statuses by ID.
9

10
**[Permissions](#permissions) required:**
11

12
 *  *Administer projects* [project permission.](https://confluence.atlassian.com/x/yodKLg)
13
 *  *Administer Jira* [project permission.](https://confluence.atlassian.com/x/yodKLg)
14
 */
15
export async function main(
16
  auth: Jira,
17
  body: {
18
    statuses: {
19
      description?: string;
20
      id: string;
21
      name: string;
22
      statusCategory: "TODO" | "IN_PROGRESS" | "DONE";
23
      [k: string]: unknown;
24
    }[];
25
  }
26
) {
27
  const url = new URL(
28
    `https://${auth.domain}.atlassian.net/rest/api/2/statuses`
29
  );
30

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