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

Jira Cloud: List Boards, Sprints, and Sprint Issues

See more Jira Examples

Find a board within a project by name, find a sprint on that board, and list its issues. Each list is paginated. Duplicate board or sprint names are treated as ambiguous; choose an ID explicitly if names are not unique.

Boards and sprints belong to the Jira Software REST API. A board's filter and the user's permissions affect what is visible. Sprints must be enabled for the selected board. Team-managed boards can have type simple even when sprints are enabled, so the discovery request does not restrict results to type=scrum. The final request uses the enhanced sprint-issue endpoint with token pagination, rather than the deprecated offset-based issue endpoint. OAuth integrations need the Jira Software scopes listed by these endpoints in addition to platform scopes.

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 sBoardName
    String sSprintName
    String sBoardId
    String sSprintId
    Integer iBoardMatches
    Integer iSprintMatches
    Integer iBoardsStart
    Boolean iBoardsMore
    Handle hoBoardsOffset
    Integer iBoardsCount
    Integer iBoardsIndex
    Integer iSprintsStart
    Boolean iSprintsMore
    Handle hoSprintsOffset
    Integer iSprintsCount
    Integer iSprintsIndex
    String sNextToken
    String sPreviousToken
    Boolean iMore
    Integer i
    String sTemp1
    String sTemp2
    String sTemp3
    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 "Example Board" To sBoardName
    Move "Sprint 1" To sSprintName
    Move "" To sBoardId
    Move "" To sSprintId
    Move 0 To iBoardMatches
    Move 0 To iSprintMatches
    Get ComSetUrlVar Of hoHttp "projectKey" "PROJECT" To iSuccess
    Get ComSetUrlVar Of hoHttp "boardName" sBoardName To iSuccess
    //  Team-managed boards can have type simple, including boards with sprints enabled.
    Move 0 To iBoardsStart
    Move True To iBoardsMore
    Get Create (RefClass(cComChilkatStringBuilder)) To hoBoardsOffset
    If (Not(IsComObjectCreated(hoBoardsOffset))) Begin
        Send CreateComObject of hoBoardsOffset
    End
    While (iBoardsMore = True)
        Send ComClear To hoBoardsOffset
        Get ComAppendInt Of hoBoardsOffset iBoardsStart To iSuccess
        Get ComGetAsString Of hoBoardsOffset To sTemp1
        Get ComSetUrlVar Of hoHttp "offset" sTemp1 To iSuccess
        Get ComSetString Of hoUrl sBaseUrl To iSuccess
        Get ComAppend Of hoUrl "/rest/agile/1.0/board?projectKeyOrId={$projectKey}&name={$boardName}&startAt={$offset}&maxResults=50" 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 "values" To iTemp1
        If (iTemp1 <> 4) Begin
            Showln "Expected an array: values"
            Procedure_Return
        End

        Get ComSizeOfArray Of hoReply "values" To iBoardsCount
        Move 0 To iBoardsIndex
        While (iBoardsIndex < iBoardsCount)
            Set ComI Of hoReply To iBoardsIndex
            Get ComStringOf Of hoReply "values[i].name" To sTemp1
            Get ComStringOf Of hoReply "values[i].id" To sTemp2
            Showln "Board: " sTemp1 "  ID: " sTemp2
            Get ComStringOfEquals Of hoReply "values[i].name" sBoardName True To bTemp1
            If (bTemp1 = True) Begin
                Get ComStringOf Of hoReply "values[i].id" To sBoardId
                Move (iBoardMatches + 1) To iBoardMatches
            End

            Move (iBoardsIndex + 1) To iBoardsIndex
        Loop

        Move (iBoardsStart + iBoardsCount) To iBoardsStart
        Get ComBoolOf Of hoReply "isLast" To bTemp1
        Move ((bTemp1 <> True)) To iBoardsMore
        If ((iBoardsMore = True) And (iBoardsCount = 0)) Begin
            Showln "Pagination made no progress; stopping."
            Procedure_Return
        End

    Loop

    If (iBoardMatches <> 1) Begin
        Showln "Expected exactly one matching board in this project."
        Procedure_Return
    End

    Get ComSetUrlVar Of hoHttp "boardId" sBoardId To iSuccess
    Move 0 To iSprintsStart
    Move True To iSprintsMore
    Get Create (RefClass(cComChilkatStringBuilder)) To hoSprintsOffset
    If (Not(IsComObjectCreated(hoSprintsOffset))) Begin
        Send CreateComObject of hoSprintsOffset
    End
    While (iSprintsMore = True)
        Send ComClear To hoSprintsOffset
        Get ComAppendInt Of hoSprintsOffset iSprintsStart To iSuccess
        Get ComGetAsString Of hoSprintsOffset To sTemp1
        Get ComSetUrlVar Of hoHttp "offset" sTemp1 To iSuccess
        Get ComSetString Of hoUrl sBaseUrl To iSuccess
        Get ComAppend Of hoUrl "/rest/agile/1.0/board/{$boardId}/sprint?startAt={$offset}&maxResults=50" 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 "values" To iTemp1
        If (iTemp1 <> 4) Begin
            Showln "Expected an array: values"
            Procedure_Return
        End

        Get ComSizeOfArray Of hoReply "values" To iSprintsCount
        Move 0 To iSprintsIndex
        While (iSprintsIndex < iSprintsCount)
            Set ComI Of hoReply To iSprintsIndex
            Get ComStringOf Of hoReply "values[i].name" To sTemp1
            Get ComStringOf Of hoReply "values[i].state" To sTemp2
            Get ComStringOf Of hoReply "values[i].id" To sTemp3
            Showln "Sprint: " sTemp1 "  " sTemp2 "  ID: " sTemp3
            Get ComStringOfEquals Of hoReply "values[i].name" sSprintName True To bTemp1
            If (bTemp1 = True) Begin
                Get ComStringOf Of hoReply "values[i].id" To sSprintId
                Move (iSprintMatches + 1) To iSprintMatches
            End

            Move (iSprintsIndex + 1) To iSprintsIndex
        Loop

        Move (iSprintsStart + iSprintsCount) To iSprintsStart
        Get ComBoolOf Of hoReply "isLast" To bTemp1
        Move ((bTemp1 <> True)) To iSprintsMore
        If ((iSprintsMore = True) And (iSprintsCount = 0)) Begin
            Showln "Pagination made no progress; stopping."
            Procedure_Return
        End

    Loop

    If (iSprintMatches <> 1) Begin
        Showln "Expected exactly one matching sprint."
        Procedure_Return
    End

    Get ComSetUrlVar Of hoHttp "sprintId" sSprintId To iSuccess
    Move "" To sNextToken
    Move "" To sPreviousToken
    Move True To iMore
    While (iMore = True)
        Get ComSetUrlVar Of hoHttp "nextToken" sNextToken To iSuccess
        Get ComSetString Of hoUrl sBaseUrl To iSuccess
        Get ComAppend Of hoUrl "/rest/software/1.0/sprint/{$sprintId}/issue?maxResults=50&fields=summary,status" To iSuccess
        If (sNextToken <> "") Begin
            Get ComAppend Of hoUrl "&nextPageToken={$nextToken}" To iSuccess
        End

        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 "issues" To iTemp1
        If (iTemp1 <> 4) Begin
            Showln "Expected an array: issues"
            Procedure_Return
        End

        Move 0 To i
        While (i < (ComSizeOfArray(hoReply, "issues")))
            Set ComI Of hoReply To i
            Get ComStringOf Of hoReply "issues[i].key" To sTemp1
            Get ComStringOf Of hoReply "issues[i].fields.summary" To sTemp2
            Showln sTemp1 "  " sTemp2
            Move (i + 1) To i
        Loop

        Get ComBoolOf Of hoReply "isLast" To bTemp1
        Move ((bTemp1 <> True)) To iMore
        If (iMore = True) Begin
            Get ComJsonTypeOf Of hoReply "nextPageToken" To iTemp1
            Get ComStringOfEquals Of hoReply "nextPageToken" "" True To bTemp1
            If ((iTemp1 <> 1) Or (bTemp1 = True)) Begin
                Showln "Missing value: nextPageToken"
                Procedure_Return
            End

            Get ComStringOf Of hoReply "nextPageToken" To sNextToken
            If (sNextToken = sPreviousToken) Begin
                Showln "Repeated pagination token; stopping."
                Procedure_Return
            End

            Move sNextToken To sPreviousToken
        End

    Loop



End_Procedure