0

Get Transitions

by
Published Nov 2, 2023

List the workflow transitions the current user can perform on an issue in its current status. Pass `expand: "transitions.fields"` to see the fields each transition screen accepts.

Script jira Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 8 days ago
1
//native
2

3
/**
4
 * Get Transitions
5
 * List the workflow transitions the current user can perform on an issue in its current status. Pass `expand: "transitions.fields"` to see the fields each transition screen accepts.
6
 */
7
export async function main(
8
  auth: RT.Jira,
9
  issue_id_or_key: string,
10
  transition_id: string | undefined,
11
  expand: string | undefined,
12
  skip_remote_only_condition: boolean | undefined,
13
  include_unavailable_transitions: boolean | undefined,
14
  sort_by_ops_bar_and_status: boolean | undefined
15
) {
16
  const url = new URL(
17
    `https://${auth.domain}.atlassian.net/rest/api/3/issue/${issue_id_or_key}/transitions`
18
  )
19
  if (transition_id != null && transition_id !== "") {
20
    url.searchParams.append("transitionId", transition_id)
21
  }
22
  if (expand != null && expand !== "") {
23
    url.searchParams.append("expand", expand)
24
  }
25
  if (skip_remote_only_condition) {
26
    url.searchParams.append("skipRemoteOnlyCondition", "true")
27
  }
28
  if (include_unavailable_transitions) {
29
    url.searchParams.append("includeUnavailableTransitions", "true")
30
  }
31
  if (sort_by_ops_bar_and_status) {
32
    url.searchParams.append("sortByOpsBarAndStatus", "true")
33
  }
34

35
  const response = await fetch(url, {
36
    method: "GET",
37
    headers: {
38
      Authorization: `Basic ${btoa(`${auth.username}:${auth.password}`)}`,
39
      Accept: "application/json",
40
    },
41
  })
42

43
  if (!response.ok) {
44
    throw new Error(`${response.status} ${await response.text()}`)
45
  }
46

47
  return await response.json()
48
}
49

Other submissions
  • Submitted by hugo697 Typescript (fetch-only)
    Created 532 days ago
    1
    type Jira = {
    2
      username: string;
    3
      password: string;
    4
      domain: string;
    5
    };
    6
    /**
    7
     * Get transitions
    8
     * Returns either all transitions or a transition that can be performed by the user on an issue, based on the issue's status.
    9
     */
    10
    export async function main(
    11
      auth: Jira,
    12
      issueIdOrKey: string,
    13
      expand: string | undefined,
    14
      transitionId: string | undefined,
    15
      skipRemoteOnlyCondition: string | undefined,
    16
      includeUnavailableTransitions: string | undefined,
    17
      sortByOpsBarAndStatus: string | undefined
    18
    ) {
    19
      const url = new URL(
    20
        `https://${auth.domain}.atlassian.net/rest/api/2/issue/${issueIdOrKey}/transitions`
    21
      );
    22
      for (const [k, v] of [
    23
        ["expand", expand],
    24
        ["transitionId", transitionId],
    25
        ["skipRemoteOnlyCondition", skipRemoteOnlyCondition],
    26
        ["includeUnavailableTransitions", includeUnavailableTransitions],
    27
        ["sortByOpsBarAndStatus", sortByOpsBarAndStatus],
    28
      ]) {
    29
        if (v !== undefined && v !== "") {
    30
          url.searchParams.append(k, v);
    31
        }
    32
      }
    33
      const response = await fetch(url, {
    34
        method: "GET",
    35
        headers: {
    36
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
    37
        },
    38
        body: undefined,
    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