Update workflow scheme

Updates company-managed and team-managed project workflow schemes.

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
 * Update workflow scheme
8
 * Updates company-managed and team-managed project workflow schemes.
9
 */
10
export async function main(
11
  auth: Jira,
12
  body: {
13
    defaultWorkflowId?: string;
14
    description: string;
15
    id: string;
16
    name: string;
17
    statusMappingsByIssueTypeOverride?: {
18
      issueTypeId: string;
19
      statusMappings: { newStatusId: string; oldStatusId: string }[];
20
    }[];
21
    statusMappingsByWorkflows?: {
22
      newWorkflowId: string;
23
      oldWorkflowId: string;
24
      statusMappings: { newStatusId: string; oldStatusId: string }[];
25
    }[];
26
    version: { id: string; versionNumber: number };
27
    workflowsForIssueTypes?: { issueTypeIds: string[]; workflowId: string }[];
28
    [k: string]: unknown;
29
  }
30
) {
31
  const url = new URL(
32
    `https://${auth.domain}.atlassian.net/rest/api/2/workflowscheme/update`
33
  );
34

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