Classic update workflow scheme

Updates a company-manged project workflow scheme, including the name, default workflow, issue type to project mappings, and more. If the workflow scheme is active (that is, being used by at least one project), then a draft workflow scheme is created or updated instead, provided that `updateDraftIfNeeded` is set to `true`. **[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
 * Classic update workflow scheme
8
 * Updates a company-manged project workflow scheme, including the name, default workflow, issue type to project mappings, and more. If the workflow scheme is active (that is, being used by at least one project), then a draft workflow scheme is created or updated instead, provided that `updateDraftIfNeeded` is set to `true`.
9

10
**[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).
11
 */
12
export async function main(
13
  auth: Jira,
14
  id: string,
15
  body: {
16
    defaultWorkflow?: string;
17
    description?: string;
18
    draft?: boolean;
19
    id?: number;
20
    issueTypeMappings?: { [k: string]: string };
21
    issueTypes?: {
22
      [k: string]: {
23
        avatarId?: number;
24
        description?: string;
25
        entityId?: string;
26
        hierarchyLevel?: number;
27
        iconUrl?: string;
28
        id?: string;
29
        name?: string;
30
        scope?: {
31
          project?: {
32
            avatarUrls?: {
33
              "16x16"?: string;
34
              "24x24"?: string;
35
              "32x32"?: string;
36
              "48x48"?: string;
37
            };
38
            id?: string;
39
            key?: string;
40
            name?: string;
41
            projectCategory?: {
42
              description?: string;
43
              id?: string;
44
              name?: string;
45
              self?: string;
46
            };
47
            projectTypeKey?: "software" | "service_desk" | "business";
48
            self?: string;
49
            simplified?: boolean;
50
          };
51
          type?: "PROJECT" | "TEMPLATE";
52
          [k: string]: unknown;
53
        };
54
        self?: string;
55
        subtask?: boolean;
56
      };
57
    };
58
    lastModified?: string;
59
    lastModifiedUser?: {
60
      accountId?: string;
61
      accountType?: "atlassian" | "app" | "customer" | "unknown";
62
      active?: boolean;
63
      applicationRoles?: {
64
        callback?: {};
65
        items?: {
66
          defaultGroups?: string[];
67
          defaultGroupsDetails?: {
68
            groupId?: string;
69
            name?: string;
70
            self?: string;
71
          }[];
72
          defined?: boolean;
73
          groupDetails?: { groupId?: string; name?: string; self?: string }[];
74
          groups?: string[];
75
          hasUnlimitedSeats?: boolean;
76
          key?: string;
77
          name?: string;
78
          numberOfSeats?: number;
79
          platform?: boolean;
80
          remainingSeats?: number;
81
          selectedByDefault?: boolean;
82
          userCount?: number;
83
          userCountDescription?: string;
84
        }[];
85
        "max-results"?: number;
86
        pagingCallback?: {};
87
        size?: number;
88
      };
89
      avatarUrls?: {
90
        "16x16"?: string;
91
        "24x24"?: string;
92
        "32x32"?: string;
93
        "48x48"?: string;
94
      };
95
      displayName?: string;
96
      emailAddress?: string;
97
      expand?: string;
98
      groups?: {
99
        callback?: {};
100
        items?: { groupId?: string; name?: string; self?: string }[];
101
        "max-results"?: number;
102
        pagingCallback?: {};
103
        size?: number;
104
      };
105
      key?: string;
106
      locale?: string;
107
      name?: string;
108
      self?: string;
109
      timeZone?: string;
110
    };
111
    name?: string;
112
    originalDefaultWorkflow?: string;
113
    originalIssueTypeMappings?: { [k: string]: string };
114
    self?: string;
115
    updateDraftIfNeeded?: boolean;
116
  }
117
) {
118
  const url = new URL(
119
    `https://${auth.domain}.atlassian.net/rest/api/2/workflowscheme/${id}`
120
  );
121

122
  const response = await fetch(url, {
123
    method: "PUT",
124
    headers: {
125
      "Content-Type": "application/json",
126
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
127
    },
128
    body: JSON.stringify(body),
129
  });
130
  if (!response.ok) {
131
    const text = await response.text();
132
    throw new Error(`${response.status} ${text}`);
133
  }
134
  return await response.json();
135
}
136