Sample code for 30+ languages & platforms
B4X 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 B4X Downloads

B4X
Dim success As Boolean = False

'  Assumes Chilkat is unlocked. See Global Unlock Sample.

Dim http As ChilkatHttp
http.Initialize("http")
http.RequireSslCertVerify = True
http.BasicAuth = True
'  Read these credentials from private application configuration.
http.Login = "YOUR_ATLASSIAN_EMAIL"
http.Password = "YOUR_API_TOKEN"
Dim baseUrl As String = "https://your-domain.atlassian.net"
http.Accept = "application/json"
Dim url As ChilkatStringBuilder
url.Initialize
Dim resp As ChilkatHttpResponse
resp.Initialize
Dim reply As ChilkatJsonObject
reply.Initialize
Dim boardName As String = "Example Board"
Dim sprintName As String = "Sprint 1"
Dim boardId As String = ""
Dim sprintId As String = ""
Dim boardMatches As Int = 0
Dim sprintMatches As Int = 0
http.SetUrlVar("projectKey", "PROJECT")
http.SetUrlVar("boardName", boardName)
'  Team-managed boards can have type simple, including boards with sprints enabled.
Dim boardsStart As Int = 0
Dim boardsMore As Boolean = True
Dim boardsOffset As ChilkatStringBuilder
boardsOffset.Initialize
Do While (boardsMore = True)
    boardsOffset.Clear
    boardsOffset.AppendInt(boardsStart)
    http.SetUrlVar("offset", boardsOffset.GetAsString)
    url.SetString(baseUrl)
    url.Append("/rest/agile/1.0/board?projectKeyOrId={$projectKey}&name={$boardName}&startAt={$offset}&maxResults=50")
    success = http.HttpNoBody("GET", url.GetAsString, resp)
    If resp.StatusCode = 0 Then
        Log("No HTTP response was received. Check connectivity and TLS settings.")
        Return
    End If

    If (success <> True) Or (resp.StatusCode < 200) Or (resp.StatusCode >= 300) Then
        Log("Request failed. HTTP " & resp.StatusCode)
        If resp.StatusCode = 429 Then
            Log("Rate limited. Retry-After: " & resp.GetHeaderField("Retry-After"))
        End If

        '  Inspect this response locally; it can contain private Jira data.
        Log(resp.BodyStr)
        Return
    End If

    success = reply.Load(resp.BodyStr)
    If success <> True Then
        Log("Expected a JSON object in the response.")
        Return
    End If

    If reply.JsonTypeOf("values") <> 4 Then
        Log("Expected an array: values")
        Return
    End If

    Dim boardsCount As Int = reply.SizeOfArray("values")
    Dim boardsIndex As Int = 0
    Do While (boardsIndex < boardsCount)
        reply.I = boardsIndex
        Log("Board: " & reply.StringOf("values[i].name") & "  ID: " & reply.StringOf("values[i].id"))
        If reply.StringOfEquals("values[i].name", boardName, True) = True Then
            boardId = reply.StringOf("values[i].id")
            boardMatches = boardMatches + 1
        End If

        boardsIndex = boardsIndex + 1
    Loop
    boardsStart = boardsStart + boardsCount
    boardsMore = (reply.BoolOf("isLast") <> True)
    If (boardsMore = True) And (boardsCount = 0) Then
        Log("Pagination made no progress; stopping.")
        Return
    End If

Loop
If boardMatches <> 1 Then
    Log("Expected exactly one matching board in this project.")
    Return
End If

http.SetUrlVar("boardId", boardId)
Dim sprintsStart As Int = 0
Dim sprintsMore As Boolean = True
Dim sprintsOffset As ChilkatStringBuilder
sprintsOffset.Initialize
Do While (sprintsMore = True)
    sprintsOffset.Clear
    sprintsOffset.AppendInt(sprintsStart)
    http.SetUrlVar("offset", sprintsOffset.GetAsString)
    url.SetString(baseUrl)
    url.Append("/rest/agile/1.0/board/{$boardId}/sprint?startAt={$offset}&maxResults=50")
    success = http.HttpNoBody("GET", url.GetAsString, resp)
    If resp.StatusCode = 0 Then
        Log("No HTTP response was received. Check connectivity and TLS settings.")
        Return
    End If

    If (success <> True) Or (resp.StatusCode < 200) Or (resp.StatusCode >= 300) Then
        Log("Request failed. HTTP " & resp.StatusCode)
        If resp.StatusCode = 429 Then
            Log("Rate limited. Retry-After: " & resp.GetHeaderField("Retry-After"))
        End If

        '  Inspect this response locally; it can contain private Jira data.
        Log(resp.BodyStr)
        Return
    End If

    success = reply.Load(resp.BodyStr)
    If success <> True Then
        Log("Expected a JSON object in the response.")
        Return
    End If

    If reply.JsonTypeOf("values") <> 4 Then
        Log("Expected an array: values")
        Return
    End If

    Dim sprintsCount As Int = reply.SizeOfArray("values")
    Dim sprintsIndex As Int = 0
    Do While (sprintsIndex < sprintsCount)
        reply.I = sprintsIndex
        Log("Sprint: " & reply.StringOf("values[i].name") & "  " & reply.StringOf("values[i].state") & "  ID: " & reply.StringOf("values[i].id"))
        If reply.StringOfEquals("values[i].name", sprintName, True) = True Then
            sprintId = reply.StringOf("values[i].id")
            sprintMatches = sprintMatches + 1
        End If

        sprintsIndex = sprintsIndex + 1
    Loop
    sprintsStart = sprintsStart + sprintsCount
    sprintsMore = (reply.BoolOf("isLast") <> True)
    If (sprintsMore = True) And (sprintsCount = 0) Then
        Log("Pagination made no progress; stopping.")
        Return
    End If

Loop
If sprintMatches <> 1 Then
    Log("Expected exactly one matching sprint.")
    Return
End If

http.SetUrlVar("sprintId", sprintId)
Dim nextToken As String = ""
Dim previousToken As String = ""
Dim more As Boolean = True
Do While (more = True)
    http.SetUrlVar("nextToken", nextToken)
    url.SetString(baseUrl)
    url.Append("/rest/software/1.0/sprint/{$sprintId}/issue?maxResults=50&fields=summary,status")
    If nextToken <> "" Then
        url.Append("&nextPageToken={$nextToken}")
    End If

    success = http.HttpNoBody("GET", url.GetAsString, resp)
    If resp.StatusCode = 0 Then
        Log("No HTTP response was received. Check connectivity and TLS settings.")
        Return
    End If

    If (success <> True) Or (resp.StatusCode < 200) Or (resp.StatusCode >= 300) Then
        Log("Request failed. HTTP " & resp.StatusCode)
        If resp.StatusCode = 429 Then
            Log("Rate limited. Retry-After: " & resp.GetHeaderField("Retry-After"))
        End If

        '  Inspect this response locally; it can contain private Jira data.
        Log(resp.BodyStr)
        Return
    End If

    success = reply.Load(resp.BodyStr)
    If success <> True Then
        Log("Expected a JSON object in the response.")
        Return
    End If

    If reply.JsonTypeOf("issues") <> 4 Then
        Log("Expected an array: issues")
        Return
    End If

    Dim i As Int = 0
    Do While (i < reply.SizeOfArray("issues"))
        reply.I = i
        Log(reply.StringOf("issues[i].key") & "  " & reply.StringOf("issues[i].fields.summary"))
        i = i + 1
    Loop
    more = (reply.BoolOf("isLast") <> True)
    If more = True Then
        If (reply.JsonTypeOf("nextPageToken") <> 1) Or (reply.StringOfEquals("nextPageToken", "", True) = True) Then
            Log("Missing value: nextPageToken")
            Return
        End If

        nextToken = reply.StringOf("nextPageToken")
        If nextToken = previousToken Then
            Log("Repeated pagination token; stopping.")
            Return
        End If

        previousToken = nextToken
    End If

Loop