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

Lazarus Pascal
program ChilkatDemo;

// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.

{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}

uses
  {$IFDEF UNIX}
  cthreads,
  {$ENDIF}
  SysUtils,
  CkDllLoader,
  Chilkat.Http,
  Chilkat.StringBuilder,
  Chilkat.HttpResponse,
  Chilkat.JsonObject;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  success: Boolean;
  http: THttp;
  baseUrl: string;
  url: TStringBuilder;
  resp: THttpResponse;
  reply: TJsonObject;
  boardName: string;
  sprintName: string;
  boardId: string;
  sprintId: string;
  boardMatches: Integer;
  sprintMatches: Integer;
  boardsStart: Integer;
  boardsMore: Boolean;
  boardsOffset: TStringBuilder;
  boardsCount: Integer;
  boardsIndex: Integer;
  sprintsStart: Integer;
  sprintsMore: Boolean;
  sprintsOffset: TStringBuilder;
  sprintsCount: Integer;
  sprintsIndex: Integer;
  nextToken: string;
  previousToken: string;
  more: Boolean;
  i: Integer;

begin
  success := False;

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

  http := THttp.Create;
  http.RequireSslCertVerify := True;
  http.BasicAuth := True;
  //  Read these credentials from private application configuration.
  http.Login := 'YOUR_ATLASSIAN_EMAIL';
  http.Password := 'YOUR_API_TOKEN';
  baseUrl := 'https://your-domain.atlassian.net';
  http.Accept := 'application/json';
  url := TStringBuilder.Create;
  resp := THttpResponse.Create;
  reply := TJsonObject.Create;
  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 := TStringBuilder.Create;
  while (boardsMore = True) do
    begin
      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
        begin
          WriteLn('No HTTP response was received. Check connectivity and TLS settings.');
          Exit;
        end;
      if ((success <> True) or (resp.StatusCode < 200) or (resp.StatusCode >= 300)) then
        begin
          WriteLn('Request failed. HTTP ' + resp.StatusCode);
          if (resp.StatusCode = 429) then
            begin
              WriteLn('Rate limited. Retry-After: ' + resp.GetHeaderField('Retry-After'));
            end;
          //  Inspect this response locally; it can contain private Jira data.
          WriteLn(resp.BodyStr);
          Exit;
        end;
      success := reply.Load(resp.BodyStr);
      if (success <> True) then
        begin
          WriteLn('Expected a JSON object in the response.');
          Exit;
        end;
      if (reply.JsonTypeOf('values') <> 4) then
        begin
          WriteLn('Expected an array: values');
          Exit;
        end;
      boardsCount := reply.SizeOfArray('values');
      boardsIndex := 0;
      while (boardsIndex < boardsCount) do
        begin
          reply.I := boardsIndex;
          WriteLn('Board: ' + reply.StringOf('values[i].name') + '  ID: ' + reply.StringOf('values[i].id'));
          if (reply.StringOfEquals('values[i].name',boardName,True) = True) then
            begin
              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)) then
        begin
          WriteLn('Pagination made no progress; stopping.');
          Exit;
        end;
    end;

  if (boardMatches <> 1) then
    begin
      WriteLn('Expected exactly one matching board in this project.');
      Exit;
    end;
  http.SetUrlVar('boardId',boardId);
  sprintsStart := 0;
  sprintsMore := True;
  sprintsOffset := TStringBuilder.Create;
  while (sprintsMore = True) do
    begin
      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
        begin
          WriteLn('No HTTP response was received. Check connectivity and TLS settings.');
          Exit;
        end;
      if ((success <> True) or (resp.StatusCode < 200) or (resp.StatusCode >= 300)) then
        begin
          WriteLn('Request failed. HTTP ' + resp.StatusCode);
          if (resp.StatusCode = 429) then
            begin
              WriteLn('Rate limited. Retry-After: ' + resp.GetHeaderField('Retry-After'));
            end;
          //  Inspect this response locally; it can contain private Jira data.
          WriteLn(resp.BodyStr);
          Exit;
        end;
      success := reply.Load(resp.BodyStr);
      if (success <> True) then
        begin
          WriteLn('Expected a JSON object in the response.');
          Exit;
        end;
      if (reply.JsonTypeOf('values') <> 4) then
        begin
          WriteLn('Expected an array: values');
          Exit;
        end;
      sprintsCount := reply.SizeOfArray('values');
      sprintsIndex := 0;
      while (sprintsIndex < sprintsCount) do
        begin
          reply.I := sprintsIndex;
          WriteLn('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
            begin
              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)) then
        begin
          WriteLn('Pagination made no progress; stopping.');
          Exit;
        end;
    end;

  if (sprintMatches <> 1) then
    begin
      WriteLn('Expected exactly one matching sprint.');
      Exit;
    end;
  http.SetUrlVar('sprintId',sprintId);
  nextToken := '';
  previousToken := '';
  more := True;
  while (more = True) do
    begin
      http.SetUrlVar('nextToken',nextToken);
      url.SetString(baseUrl);
      url.Append('/rest/software/1.0/sprint/{$sprintId}/issue?maxResults=50&fields=summary,status');
      if (nextToken <> '') then
        begin
          url.Append('&nextPageToken={$nextToken}');
        end;
      success := http.HttpNoBody('GET',url.GetAsString(),resp);
      if (resp.StatusCode = 0) then
        begin
          WriteLn('No HTTP response was received. Check connectivity and TLS settings.');
          Exit;
        end;
      if ((success <> True) or (resp.StatusCode < 200) or (resp.StatusCode >= 300)) then
        begin
          WriteLn('Request failed. HTTP ' + resp.StatusCode);
          if (resp.StatusCode = 429) then
            begin
              WriteLn('Rate limited. Retry-After: ' + resp.GetHeaderField('Retry-After'));
            end;
          //  Inspect this response locally; it can contain private Jira data.
          WriteLn(resp.BodyStr);
          Exit;
        end;
      success := reply.Load(resp.BodyStr);
      if (success <> True) then
        begin
          WriteLn('Expected a JSON object in the response.');
          Exit;
        end;
      if (reply.JsonTypeOf('issues') <> 4) then
        begin
          WriteLn('Expected an array: issues');
          Exit;
        end;
      i := 0;
      while (i < reply.SizeOfArray('issues')) do
        begin
          reply.I := i;
          WriteLn(reply.StringOf('issues[i].key') + '  ' + reply.StringOf('issues[i].fields.summary'));
          i := i + 1;
        end;

      more := (reply.BoolOf('isLast') <> True);
      if (more = True) then
        begin
          if ((reply.JsonTypeOf('nextPageToken') <> 1) or (reply.StringOfEquals('nextPageToken','',True) = True)) then
            begin
              WriteLn('Missing value: nextPageToken');
              Exit;
            end;
          nextToken := reply.StringOf('nextPageToken');
          if (nextToken = previousToken) then
            begin
              WriteLn('Repeated pagination token; stopping.');
              Exit;
            end;
          previousToken := nextToken;
        end;
    end;



  http.Free;
  url.Free;
  resp.Free;
  reply.Free;
  boardsOffset.Free;
  sprintsOffset.Free;

end;

// ---------------------------------------------------------------------------

begin

  try
    RunDemo;
  except
    on E: Exception do
      WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
  end;

  WriteLn;
  {$IFDEF MSWINDOWS}
  WriteLn('Press Enter to exit...');
  ReadLn;
  {$ENDIF}
end.