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

CkJava
import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    boolean success = false;

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

    CkHttp http = new CkHttp();
    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");
    String baseUrl = "https://your-domain.atlassian.net";
    http.put_Accept("application/json");
    CkStringBuilder url = new CkStringBuilder();
    CkHttpResponse resp = new CkHttpResponse();
    CkJsonObject reply = new CkJsonObject();
    String boardName = "Example Board";
    String sprintName = "Sprint 1";
    String boardId = "";
    String sprintId = "";
    int boardMatches = 0;
    int sprintMatches = 0;
    http.SetUrlVar("projectKey","PROJECT");
    http.SetUrlVar("boardName",boardName);
    //  Team-managed boards can have type simple, including boards with sprints enabled.
    int boardsStart = 0;
    boolean boardsMore = true;
    CkStringBuilder boardsOffset = new CkStringBuilder();
    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) {
            System.out.println("No HTTP response was received. Check connectivity and TLS settings.");
            return;
            }

        if ((success != true) || (resp.get_StatusCode() < 200) || (resp.get_StatusCode() >= 300)) {
            System.out.println("Request failed. HTTP " + resp.get_StatusCode());
            if (resp.get_StatusCode() == 429) {
                System.out.println("Rate limited. Retry-After: " + resp.getHeaderField("Retry-After"));
                }

            //  Inspect this response locally; it can contain private Jira data.
            System.out.println(resp.bodyStr());
            return;
            }

        success = reply.Load(resp.bodyStr());
        if (success != true) {
            System.out.println("Expected a JSON object in the response.");
            return;
            }

        if (reply.JsonTypeOf("values") != 4) {
            System.out.println("Expected an array: values");
            return;
            }

        int boardsCount = reply.SizeOfArray("values");
        int boardsIndex = 0;
        while ((boardsIndex < boardsCount)) {
            reply.put_I(boardsIndex);
            System.out.println("Board: " + reply.stringOf("values[i].name") + "  ID: " + reply.stringOf("values[i].id"));
            if (reply.StringOfEquals("values[i].name",boardName,true) == true) {
                boardId = reply.stringOf("values[i].id");
                boardMatches = boardMatches+1;
                }

            boardsIndex = boardsIndex+1;
            }

        boardsStart = boardsStart+boardsCount;
        boardsMore = (reply.BoolOf("isLast") != true);
        if ((boardsMore == true) && (boardsCount == 0)) {
            System.out.println("Pagination made no progress; stopping.");
            return;
            }

        }

    if (boardMatches != 1) {
        System.out.println("Expected exactly one matching board in this project.");
        return;
        }

    http.SetUrlVar("boardId",boardId);
    int sprintsStart = 0;
    boolean sprintsMore = true;
    CkStringBuilder sprintsOffset = new CkStringBuilder();
    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) {
            System.out.println("No HTTP response was received. Check connectivity and TLS settings.");
            return;
            }

        if ((success != true) || (resp.get_StatusCode() < 200) || (resp.get_StatusCode() >= 300)) {
            System.out.println("Request failed. HTTP " + resp.get_StatusCode());
            if (resp.get_StatusCode() == 429) {
                System.out.println("Rate limited. Retry-After: " + resp.getHeaderField("Retry-After"));
                }

            //  Inspect this response locally; it can contain private Jira data.
            System.out.println(resp.bodyStr());
            return;
            }

        success = reply.Load(resp.bodyStr());
        if (success != true) {
            System.out.println("Expected a JSON object in the response.");
            return;
            }

        if (reply.JsonTypeOf("values") != 4) {
            System.out.println("Expected an array: values");
            return;
            }

        int sprintsCount = reply.SizeOfArray("values");
        int sprintsIndex = 0;
        while ((sprintsIndex < sprintsCount)) {
            reply.put_I(sprintsIndex);
            System.out.println("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) {
                sprintId = reply.stringOf("values[i].id");
                sprintMatches = sprintMatches+1;
                }

            sprintsIndex = sprintsIndex+1;
            }

        sprintsStart = sprintsStart+sprintsCount;
        sprintsMore = (reply.BoolOf("isLast") != true);
        if ((sprintsMore == true) && (sprintsCount == 0)) {
            System.out.println("Pagination made no progress; stopping.");
            return;
            }

        }

    if (sprintMatches != 1) {
        System.out.println("Expected exactly one matching sprint.");
        return;
        }

    http.SetUrlVar("sprintId",sprintId);
    String nextToken = "";
    String previousToken = "";
    boolean 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}");
            }

        success = http.HttpNoBody("GET",url.getAsString(),resp);
        if (resp.get_StatusCode() == 0) {
            System.out.println("No HTTP response was received. Check connectivity and TLS settings.");
            return;
            }

        if ((success != true) || (resp.get_StatusCode() < 200) || (resp.get_StatusCode() >= 300)) {
            System.out.println("Request failed. HTTP " + resp.get_StatusCode());
            if (resp.get_StatusCode() == 429) {
                System.out.println("Rate limited. Retry-After: " + resp.getHeaderField("Retry-After"));
                }

            //  Inspect this response locally; it can contain private Jira data.
            System.out.println(resp.bodyStr());
            return;
            }

        success = reply.Load(resp.bodyStr());
        if (success != true) {
            System.out.println("Expected a JSON object in the response.");
            return;
            }

        if (reply.JsonTypeOf("issues") != 4) {
            System.out.println("Expected an array: issues");
            return;
            }

        int i = 0;
        while ((i < reply.SizeOfArray("issues"))) {
            reply.put_I(i);
            System.out.println(reply.stringOf("issues[i].key") + "  " + reply.stringOf("issues[i].fields.summary"));
            i = i+1;
            }

        more = (reply.BoolOf("isLast") != true);
        if (more == true) {
            if ((reply.JsonTypeOf("nextPageToken") != 1) || (reply.StringOfEquals("nextPageToken","",true) == true)) {
                System.out.println("Missing value: nextPageToken");
                return;
                }

            nextToken = reply.stringOf("nextPageToken");
            if (nextToken == previousToken) {
                System.out.println("Repeated pagination token; stopping.");
                return;
                }

            previousToken = nextToken;
            }

        }
  }
}