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

Lua
local chilkat = require("chilkat")

local success = false

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

local http = chilkat.Http.new()
http.require_ssl_cert_verify = true
http.basic_auth = true
-- Read these credentials from private application configuration.
http.login = "YOUR_ATLASSIAN_EMAIL"
http.password = "YOUR_API_TOKEN"
local baseUrl = "https://your-domain.atlassian.net"
http.accept = "application/json"
local url = chilkat.StringBuilder.new()
local resp = chilkat.HttpResponse.new()
local reply = chilkat.JsonObject.new()
local boardName = "Example Board"
local sprintName = "Sprint 1"
local boardId = ""
local sprintId = ""
local boardMatches = 0
local sprintMatches = 0
http:set_url_var("projectKey", "PROJECT")
http:set_url_var("boardName", boardName)
-- Team-managed boards can have type simple, including boards with sprints enabled.
local boardsStart = 0
local boardsMore = true
local boardsOffset = chilkat.StringBuilder.new()
while boardsMore do
    boardsOffset:clear()
    boardsOffset:append_int(boardsStart)
    http:set_url_var("offset", boardsOffset:get_as_string())
    url:set_string(baseUrl)
    url:append("/rest/agile/1.0/board?projectKeyOrId={$projectKey}&name={$boardName}&startAt={$offset}&maxResults=50")
    success = http:http_no_body("GET", url:get_as_string(), resp)
    if resp.status_code == 0 then
        print("No HTTP response was received. Check connectivity and TLS settings.")
        return
    end

    if (not success) or ((resp.status_code < 200) or (resp.status_code >= 300)) then
        print("Request failed. HTTP " .. resp.status_code)
        if resp.status_code == 429 then
            print("Rate limited. Retry-After: " .. resp:get_header_field("Retry-After"))
        end

        -- Inspect this response locally; it can contain private Jira data.
        print(resp.body_str)
        return
    end

    success = reply:load(resp.body_str)
    if not success then
        print("Expected a JSON object in the response.")
        return
    end

    if reply:json_type_of("values") ~= 4 then
        print("Expected an array: values")
        return
    end

    local boardsCount = reply:size_of_array("values")
    local boardsIndex = 0
    while boardsIndex < boardsCount do
        reply.i = boardsIndex
        print("Board: " .. reply:string_of("values[i].name") .. "  ID: " .. reply:string_of("values[i].id"))
        if reply:string_of_equals("values[i].name", boardName, true) then
            boardId = reply:string_of("values[i].id")
            boardMatches = boardMatches + 1
        end

        boardsIndex = boardsIndex + 1
    end

    boardsStart = boardsStart + boardsCount
    boardsMore = (not reply:bool_of("isLast"))
    if (boardsMore) and (boardsCount == 0) then
        print("Pagination made no progress; stopping.")
        return
    end
end

if boardMatches ~= 1 then
    print("Expected exactly one matching board in this project.")
    return
end

http:set_url_var("boardId", boardId)
local sprintsStart = 0
local sprintsMore = true
local sprintsOffset = chilkat.StringBuilder.new()
while sprintsMore do
    sprintsOffset:clear()
    sprintsOffset:append_int(sprintsStart)
    http:set_url_var("offset", sprintsOffset:get_as_string())
    url:set_string(baseUrl)
    url:append("/rest/agile/1.0/board/{$boardId}/sprint?startAt={$offset}&maxResults=50")
    success = http:http_no_body("GET", url:get_as_string(), resp)
    if resp.status_code == 0 then
        print("No HTTP response was received. Check connectivity and TLS settings.")
        return
    end

    if (not success) or ((resp.status_code < 200) or (resp.status_code >= 300)) then
        print("Request failed. HTTP " .. resp.status_code)
        if resp.status_code == 429 then
            print("Rate limited. Retry-After: " .. resp:get_header_field("Retry-After"))
        end

        -- Inspect this response locally; it can contain private Jira data.
        print(resp.body_str)
        return
    end

    success = reply:load(resp.body_str)
    if not success then
        print("Expected a JSON object in the response.")
        return
    end

    if reply:json_type_of("values") ~= 4 then
        print("Expected an array: values")
        return
    end

    local sprintsCount = reply:size_of_array("values")
    local sprintsIndex = 0
    while sprintsIndex < sprintsCount do
        reply.i = sprintsIndex
        print("Sprint: " .. reply:string_of("values[i].name") .. "  " .. reply:string_of("values[i].state") .. "  ID: " .. reply:string_of("values[i].id"))
        if reply:string_of_equals("values[i].name", sprintName, true) then
            sprintId = reply:string_of("values[i].id")
            sprintMatches = sprintMatches + 1
        end

        sprintsIndex = sprintsIndex + 1
    end

    sprintsStart = sprintsStart + sprintsCount
    sprintsMore = (not reply:bool_of("isLast"))
    if (sprintsMore) and (sprintsCount == 0) then
        print("Pagination made no progress; stopping.")
        return
    end
end

if sprintMatches ~= 1 then
    print("Expected exactly one matching sprint.")
    return
end

http:set_url_var("sprintId", sprintId)
local nextToken = ""
local previousToken = ""
local more = true
while more do
    http:set_url_var("nextToken", nextToken)
    url:set_string(baseUrl)
    url:append("/rest/software/1.0/sprint/{$sprintId}/issue?maxResults=50&fields=summary,status")
    if nextToken ~= "" then
        url:append("&nextPageToken={$nextToken}")
    end

    success = http:http_no_body("GET", url:get_as_string(), resp)
    if resp.status_code == 0 then
        print("No HTTP response was received. Check connectivity and TLS settings.")
        return
    end

    if (not success) or ((resp.status_code < 200) or (resp.status_code >= 300)) then
        print("Request failed. HTTP " .. resp.status_code)
        if resp.status_code == 429 then
            print("Rate limited. Retry-After: " .. resp:get_header_field("Retry-After"))
        end

        -- Inspect this response locally; it can contain private Jira data.
        print(resp.body_str)
        return
    end

    success = reply:load(resp.body_str)
    if not success then
        print("Expected a JSON object in the response.")
        return
    end

    if reply:json_type_of("issues") ~= 4 then
        print("Expected an array: issues")
        return
    end

    local i = 0
    while i < reply:size_of_array("issues") do
        reply.i = i
        print(reply:string_of("issues[i].key") .. "  " .. reply:string_of("issues[i].fields.summary"))
        i = i + 1
    end

    more = (not reply:bool_of("isLast"))
    if more then
        if (reply:json_type_of("nextPageToken") ~= 1) or (reply:string_of_equals("nextPageToken", "", true)) then
            print("Missing value: nextPageToken")
            return
        end

        nextToken = reply:string_of("nextPageToken")
        if nextToken == previousToken then
            print("Repeated pagination token; stopping.")
            return
        end

        previousToken = nextToken
    end
end