Create workflow scheme

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

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