Bulk get workflows

Returns a list of workflows and related statuses by providing workflow names, workflow IDs, or project and issue types. **[Permissions](#permissions) required:** * *Administer Jira* global permission to access all, including project-scoped, workflows * At least one of the *Administer projects* and *View (read-only) workflow* project permissions to access 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
 * Bulk get workflows
8
 * Returns a list of workflows and related statuses by providing workflow names, workflow IDs, or project and issue types.
9

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

12
 *  *Administer Jira* global permission to access all, including project-scoped, workflows
13
 *  At least one of the *Administer projects* and *View (read-only) workflow* project permissions to access project-scoped workflows
14
 */
15
export async function main(
16
  auth: Jira,
17
  expand: string | undefined,
18
  body: {
19
    projectAndIssueTypes?: { issueTypeId: string; projectId: string }[];
20
    workflowIds?: string[];
21
    workflowNames?: string[];
22
  }
23
) {
24
  const url = new URL(
25
    `https://${auth.domain}.atlassian.net/rest/api/2/workflows`
26
  );
27
  for (const [k, v] of [["expand", expand]]) {
28
    if (v !== undefined && v !== "") {
29
      url.searchParams.append(k, v);
30
    }
31
  }
32
  const response = await fetch(url, {
33
    method: "POST",
34
    headers: {
35
      "Content-Type": "application/json",
36
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
37
    },
38
    body: JSON.stringify(body),
39
  });
40
  if (!response.ok) {
41
    const text = await response.text();
42
    throw new Error(`${response.status} ${text}`);
43
  }
44
  return await response.json();
45
}
46