Sample code for 30+ languages & platforms
DataFlex Requires Chilkat v11.0.0+

Jira Cloud: Change an Issue Status

See more Jira Examples

List the workflow transitions currently available to an issue and execute the transition selected by name. A transition is an action, not merely a destination status: use the name returned by Jira, and do not assume the ID or name is the same in every project.

The expanded transition metadata identifies fields associated with transition screens. This basic example refuses a transition with required fields so it cannot silently omit them. Adapt the POST body with the required fields before using such a transition. Workflow conditions and validators can still reject a request, and the available transitions can change between GET and POST.

The code uses an Atlassian account email and an API token without scopes with the site URL. For a scoped API token, keep Basic authentication and change baseUrl to https://api.atlassian.com/ex/jira/YOUR_CLOUD_ID. For OAuth2, use that gateway URL, omit Login/Password/BasicAuth, and set http.AuthToken to the access token. See API token authentication and OAuth2 authorization. The account must have permission for the operation; OAuth scopes do not grant additional Jira permissions.

Targets Jira Cloud. Jira Data Center has a separate REST API and may require different paths, authentication, or payloads.

Atlassian REST API documentation

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoHttp
    String sBaseUrl
    Handle hoUrl
    Variant vResp
    Handle hoResp
    Handle hoReply
    String sIssueKey
    String sTransitionName
    String sTransitionId
    Integer iMatches
    Boolean iNeedsFields
    Integer i
    Integer j
s    Handle hoFields
    Handle hoField
    Variant vRequest
    Handle hoRequest
    String sTemp1
    String sTemp2
    Integer iTemp1
    Integer iTemp2
    Boolean bTemp1

    Move False To iSuccess

    //  Assumes Chilkat is unlocked. See Global Unlock Sample.

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End
    Set ComRequireSslCertVerify Of hoHttp To True
    Set ComBasicAuth Of hoHttp To True
    //  Read these credentials from private application configuration.
    Set ComLogin Of hoHttp To "YOUR_ATLASSIAN_EMAIL"
    Set ComPassword Of hoHttp To "YOUR_API_TOKEN"
    Move "https://your-domain.atlassian.net" To sBaseUrl
    Set ComAccept Of hoHttp To "application/json"
    Get Create (RefClass(cComChilkatStringBuilder)) To hoUrl
    If (Not(IsComObjectCreated(hoUrl))) Begin
        Send CreateComObject of hoUrl
    End
    Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
    If (Not(IsComObjectCreated(hoResp))) Begin
        Send CreateComObject of hoResp
    End
    Get Create (RefClass(cComChilkatJsonObject)) To hoReply
    If (Not(IsComObjectCreated(hoReply))) Begin
        Send CreateComObject of hoReply
    End
    Move "PROJECT-123" To sIssueKey
    Get ComSetUrlVar Of hoHttp "issueKey" sIssueKey To iSuccess
    Move "Start Progress" To sTransitionName
    Move "" To sTransitionId
    Move 0 To iMatches
    Move False To iNeedsFields
    Get ComSetString Of hoUrl sBaseUrl To iSuccess
    Get ComAppend Of hoUrl "/rest/api/3/issue/{$issueKey}/transitions?expand=transitions.fields" To iSuccess
    Get ComGetAsString Of hoUrl To sTemp1
    Get pvComObject of hoResp to vResp
    Get ComHttpNoBody Of hoHttp "GET" sTemp1 vResp To iSuccess
    Get ComStatusCode Of hoResp To iTemp1
    If (iTemp1 = 0) Begin
        Showln "No HTTP response was received. Check connectivity and TLS settings."
        Procedure_Return
    End

    Get ComStatusCode Of hoResp To iTemp1
    Get ComStatusCode Of hoResp To iTemp2
    If ((iSuccess <> True) Or (iTemp1 < 200) Or (iTemp2 >= 300)) Begin
        Get ComStatusCode Of hoResp To iTemp1
        Showln "Request failed. HTTP " iTemp1
        Get ComStatusCode Of hoResp To iTemp1
        If (iTemp1 = 429) Begin
            Get ComGetHeaderField Of hoResp "Retry-After" To sTemp1
            Showln "Rate limited. Retry-After: " sTemp1
        End

        //  Inspect this response locally; it can contain private Jira data.
        Get ComBodyStr Of hoResp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComBodyStr Of hoResp To sTemp1
    Get ComLoad Of hoReply sTemp1 To iSuccess
    If (iSuccess <> True) Begin
        Showln "Expected a JSON object in the response."
        Procedure_Return
    End

    Get ComJsonTypeOf Of hoReply "transitions" To iTemp1
    If (iTemp1 <> 4) Begin
        Showln "Expected an array: transitions"
        Procedure_Return
    End

    Move 0 To i
    Move 0 To j
    Get Create (RefClass(cComChilkatJsonObject)) To hoFields
    If (Not(IsComObjectCreated(hoFields))) Begin
        Send CreateComObject of hoFields
    End
    Get Create (RefClass(cComChilkatJsonObject)) To hoField
    If (Not(IsComObjectCreated(hoField))) Begin
        Send CreateComObject of hoField
    End
    While (i < (ComSizeOfArray(hoReply, "transitions")))
        Set ComI Of hoReply To i
        Get ComStringOf Of hoReply "transitions[i].name" To sTemp1
        Get ComStringOf Of hoReply "transitions[i].to.name" To sTemp2
        Showln sTemp1 " -> " sTemp2
        Get ComStringOfEquals Of hoReply "transitions[i].name" sTransitionName True To bTemp1
        If (bTemp1 = True) Begin
            Get ComStringOf Of hoReply "transitions[i].id" To sTransitionId
            Move (iMatches + 1) To iMatches
            Get ComObjectOf Of hoReply "transitions[i].fields" To vFields
            If (IsComObject(vFields)) Begin
                Get Create (RefClass(cComChilkatJsonObject)) To hoFields
                Set pvComObject Of hoFields To vFields
            End
            Get ComLastMethodSuccess Of hoReply To bTemp1
            If (bTemp1 <> True) Begin
                Showln "Expected expanded transition field metadata."
                Procedure_Return
            End

            Move 0 To j
            While (j < (ComSize(hoFields)))
                Get ComObjectAt Of hoFields j To vField
                If (IsComObject(vField)) Begin
                    Get Create (RefClass(cComChilkatJsonObject)) To hoField
                    Set pvComObject Of hoField To vField
                End
                Get ComBoolOf Of hoField "required" To bTemp1
                If (bTemp1 = True) Begin
                    Move True To iNeedsFields
                    Get ComNameAt Of hoFields j To sTemp1
                    Showln "Required transition field: " sTemp1
                End

                Send Destroy of hoField
                Move (j + 1) To j
            Loop

            Send Destroy of hoFields
        End

        Move (i + 1) To i
    Loop

    If ((iMatches <> 1) Or (iNeedsFields = True)) Begin
        Showln "Choose one available transition and supply any required transition fields before submitting."
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatJsonObject)) To hoRequest
    If (Not(IsComObjectCreated(hoRequest))) Begin
        Send CreateComObject of hoRequest
    End
    Get ComUpdateString Of hoRequest "transition.id" sTransitionId To iSuccess
    Get ComSetString Of hoUrl sBaseUrl To iSuccess
    Get ComAppend Of hoUrl "/rest/api/3/issue/{$issueKey}/transitions" To iSuccess
    Get ComGetAsString Of hoUrl To sTemp1
    Get pvComObject of hoRequest to vRequest
    Get pvComObject of hoResp to vResp
    Get ComHttpJson Of hoHttp "POST" sTemp1 vRequest "application/json" vResp To iSuccess
    Get ComStatusCode Of hoResp To iTemp1
    If (iTemp1 = 0) Begin
        Showln "No HTTP response was received. Check connectivity and TLS settings."
        Procedure_Return
    End

    Get ComStatusCode Of hoResp To iTemp1
    Get ComStatusCode Of hoResp To iTemp2
    If ((iSuccess <> True) Or (iTemp1 < 200) Or (iTemp2 >= 300)) Begin
        Get ComStatusCode Of hoResp To iTemp1
        Showln "Request failed. HTTP " iTemp1
        Get ComStatusCode Of hoResp To iTemp1
        If (iTemp1 = 429) Begin
            Get ComGetHeaderField Of hoResp "Retry-After" To sTemp1
            Showln "Rate limited. Retry-After: " sTemp1
        End

        //  Inspect this response locally; it can contain private Jira data.
        Get ComBodyStr Of hoResp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Showln "Transition completed: " sTransitionName


End_Procedure