Validate create workflows

Validate the payload for bulk create workflows. **[Permissions](#permissions) required:** * *Administer Jira* project permission to create all, including global-scoped, workflows * *Administer projects* project permissions to create project-scoped workflows

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
 * Validate create workflows
8
 * Validate the payload for bulk create workflows.
9

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

12
 *  *Administer Jira* project permission to create all, including global-scoped, workflows
13
 *  *Administer projects* project permissions to create project-scoped workflows
14
 */
15
export async function main(
16
  auth: Jira,
17
  body: {
18
    payload: {
19
      scope: { project?: { id: string }; type: "PROJECT" | "GLOBAL" };
20
      statuses: {
21
        description?: string;
22
        id?: string;
23
        name: string;
24
        statusCategory: "TODO" | "IN_PROGRESS" | "DONE";
25
        statusReference: string;
26
        [k: string]: unknown;
27
      }[];
28
      workflows: {
29
        description?: string;
30
        name: string;
31
        startPointLayout?: { x?: number; y?: number };
32
        statuses: {
33
          layout?: { x?: number; y?: number };
34
          properties: { [k: string]: string };
35
          statusReference: string;
36
          [k: string]: unknown;
37
        }[];
38
        transitions: {
39
          actions?: {
40
            id?: string;
41
            parameters?: { [k: string]: string };
42
            ruleKey: string;
43
          }[];
44
          conditions?: {
45
            conditionGroups?: {}[];
46
            conditions?: {
47
              id?: string;
48
              parameters?: { [k: string]: string };
49
              ruleKey: string;
50
            }[];
51
            operation: "ANY" | "ALL";
52
          };
53
          customIssueEventId?: string;
54
          description?: string;
55
          from?: { port?: number; statusReference: string }[];
56
          id: string;
57
          name: string;
58
          properties?: { [k: string]: string };
59
          to?: { port?: number; statusReference: string };
60
          transitionScreen?: {
61
            id?: string;
62
            parameters?: { [k: string]: string };
63
            ruleKey: string;
64
          };
65
          triggers?: {
66
            id?: string;
67
            parameters: { [k: string]: string };
68
            ruleKey: string;
69
          }[];
70
          type: "INITIAL" | "GLOBAL" | "DIRECTED";
71
          validators?: {
72
            id?: string;
73
            parameters?: { [k: string]: string };
74
            ruleKey: string;
75
          }[];
76
          [k: string]: unknown;
77
        }[];
78
      }[];
79
    };
80
    validationOptions?: { levels?: ("WARNING" | "ERROR")[] };
81
  }
82
) {
83
  const url = new URL(
84
    `https://${auth.domain}.atlassian.net/rest/api/2/workflows/create/validation`
85
  );
86

87
  const response = await fetch(url, {
88
    method: "POST",
89
    headers: {
90
      "Content-Type": "application/json",
91
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
92
    },
93
    body: JSON.stringify(body),
94
  });
95
  if (!response.ok) {
96
    const text = await response.text();
97
    throw new Error(`${response.status} ${text}`);
98
  }
99
  return await response.json();
100
}
101