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

Ruby
require 'chilkat'

success = false

#  Assumes Chilkat is unlocked. See Global Unlock Sample.

http = Chilkat::CkHttp.new()
http.put_RequireSslCertVerify(true)
http.put_BasicAuth(true)
#  Read these credentials from private application configuration.
http.put_Login("YOUR_ATLASSIAN_EMAIL")
http.put_Password("YOUR_API_TOKEN")
baseUrl = "https://your-domain.atlassian.net"
http.put_Accept("application/json")
url = Chilkat::CkStringBuilder.new()
resp = Chilkat::CkHttpResponse.new()
reply = Chilkat::CkJsonObject.new()
boardName = "Example Board"
sprintName = "Sprint 1"
boardId = ""
sprintId = ""
boardMatches = 0
sprintMatches = 0
http.SetUrlVar("projectKey","PROJECT")
http.SetUrlVar("boardName",boardName)
#  Team-managed boards can have type simple, including boards with sprints enabled.
boardsStart = 0
boardsMore = true
boardsOffset = Chilkat::CkStringBuilder.new()
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.get_StatusCode() == 0)
        print "No HTTP response was received. Check connectivity and TLS settings." + "\n";
        exit
    end

    if ((success != true) or (resp.get_StatusCode() < 200) or (resp.get_StatusCode() >= 300))
        print "Request failed. HTTP " + resp.get_StatusCode().to_s() + "\n";
        if (resp.get_StatusCode() == 429)
            print "Rate limited. Retry-After: " + resp.getHeaderField("Retry-After") + "\n";
        end

        #  Inspect this response locally; it can contain private Jira data.
        print resp.bodyStr() + "\n";
        exit
    end

    success = reply.Load(resp.bodyStr())
    if (success != true)
        print "Expected a JSON object in the response." + "\n";
        exit
    end

    if (reply.JsonTypeOf("values") != 4)
        print "Expected an array: values" + "\n";
        exit
    end

    boardsCount = reply.SizeOfArray("values")
    boardsIndex = 0
    while (boardsIndex < boardsCount)
        reply.put_I(boardsIndex)
        print "Board: " + reply.stringOf("values[i].name") + "  ID: " + reply.stringOf("values[i].id") + "\n";
        if (reply.StringOfEquals("values[i].name",boardName,true) == true)
            boardId = reply.stringOf("values[i].id")
            boardMatches = boardMatches + 1
        end

        boardsIndex = boardsIndex + 1
    end
    boardsStart = boardsStart + boardsCount
    boardsMore = (reply.BoolOf("isLast") != true)
    if ((boardsMore == true) and (boardsCount == 0))
        print "Pagination made no progress; stopping." + "\n";
        exit
    end

end
if (boardMatches != 1)
    print "Expected exactly one matching board in this project." + "\n";
    exit
end

http.SetUrlVar("boardId",boardId)
sprintsStart = 0
sprintsMore = true
sprintsOffset = Chilkat::CkStringBuilder.new()
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.get_StatusCode() == 0)
        print "No HTTP response was received. Check connectivity and TLS settings." + "\n";
        exit
    end

    if ((success != true) or (resp.get_StatusCode() < 200) or (resp.get_StatusCode() >= 300))
        print "Request failed. HTTP " + resp.get_StatusCode().to_s() + "\n";
        if (resp.get_StatusCode() == 429)
            print "Rate limited. Retry-After: " + resp.getHeaderField("Retry-After") + "\n";
        end

        #  Inspect this response locally; it can contain private Jira data.
        print resp.bodyStr() + "\n";
        exit
    end

    success = reply.Load(resp.bodyStr())
    if (success != true)
        print "Expected a JSON object in the response." + "\n";
        exit
    end

    if (reply.JsonTypeOf("values") != 4)
        print "Expected an array: values" + "\n";
        exit
    end

    sprintsCount = reply.SizeOfArray("values")
    sprintsIndex = 0
    while (sprintsIndex < sprintsCount)
        reply.put_I(sprintsIndex)
        print "Sprint: " + reply.stringOf("values[i].name") + "  " + reply.stringOf("values[i].state") + "  ID: " + reply.stringOf("values[i].id") + "\n";
        if (reply.StringOfEquals("values[i].name",sprintName,true) == true)
            sprintId = reply.stringOf("values[i].id")
            sprintMatches = sprintMatches + 1
        end

        sprintsIndex = sprintsIndex + 1
    end
    sprintsStart = sprintsStart + sprintsCount
    sprintsMore = (reply.BoolOf("isLast") != true)
    if ((sprintsMore == true) and (sprintsCount == 0))
        print "Pagination made no progress; stopping." + "\n";
        exit
    end

end
if (sprintMatches != 1)
    print "Expected exactly one matching sprint." + "\n";
    exit
end

http.SetUrlVar("sprintId",sprintId)
nextToken = ""
previousToken = ""
more = true
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 != "")
        url.Append("&nextPageToken={$nextToken}")
    end

    success = http.HttpNoBody("GET",url.getAsString(),resp)
    if (resp.get_StatusCode() == 0)
        print "No HTTP response was received. Check connectivity and TLS settings." + "\n";
        exit
    end

    if ((success != true) or (resp.get_StatusCode() < 200) or (resp.get_StatusCode() >= 300))
        print "Request failed. HTTP " + resp.get_StatusCode().to_s() + "\n";
        if (resp.get_StatusCode() == 429)
            print "Rate limited. Retry-After: " + resp.getHeaderField("Retry-After") + "\n";
        end

        #  Inspect this response locally; it can contain private Jira data.
        print resp.bodyStr() + "\n";
        exit
    end

    success = reply.Load(resp.bodyStr())
    if (success != true)
        print "Expected a JSON object in the response." + "\n";
        exit
    end

    if (reply.JsonTypeOf("issues") != 4)
        print "Expected an array: issues" + "\n";
        exit
    end

    i = 0
    while (i < reply.SizeOfArray("issues"))
        reply.put_I(i)
        print reply.stringOf("issues[i].key") + "  " + reply.stringOf("issues[i].fields.summary") + "\n";
        i = i + 1
    end
    more = (reply.BoolOf("isLast") != true)
    if (more == true)
        if ((reply.JsonTypeOf("nextPageToken") != 1) or (reply.StringOfEquals("nextPageToken","",true) == true))
            print "Missing value: nextPageToken" + "\n";
            exit
        end

        nextToken = reply.stringOf("nextPageToken")
        if (nextToken == previousToken)
            print "Repeated pagination token; stopping." + "\n";
            exit
        end

        previousToken = nextToken
    end

end