Jira Cloud: Search Issues with JQL
See more Jira Examples
Use enhanced JQL search to retrieve selected issue fields across every page. Sending JQL in a JSON POST body avoids URL-length and query-encoding problems. The current endpoint uses nextPageToken; do not substitute startAt or use the deprecated /rest/api/3/search endpoint.
Results include only issues visible to the account. Recent changes can take time to appear in search. If immediate read-after-write consistency is needed, use the endpoint's reconcileIssues option with the affected numeric issue IDs, or retrieve a known issue directly. A pagination token belongs to the same query and selected fields.
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 Delphi DLL Downloads
var
success: Boolean;
http: HCkHttp;
baseUrl: PWideChar;
url: HCkStringBuilder;
resp: HCkHttpResponse;
reply: HCkJsonObject;
request: HCkJsonObject;
previousToken: PWideChar;
nextToken: PWideChar;
more: Boolean;
count: Integer;
i: Integer;
begin
success := False;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
http := CkHttp_Create();
CkHttp_putRequireSslCertVerify(http,True);
CkHttp_putBasicAuth(http,True);
// Read these credentials from private application configuration.
CkHttp_putLogin(http,'YOUR_ATLASSIAN_EMAIL');
CkHttp_putPassword(http,'YOUR_API_TOKEN');
baseUrl := 'https://your-domain.atlassian.net';
CkHttp_putAccept(http,'application/json');
url := CkStringBuilder_Create();
resp := CkHttpResponse_Create();
reply := CkJsonObject_Create();
request := CkJsonObject_Create();
// Bound the query to a project. Adapt the JQL to your permissions and needs.
CkJsonObject_UpdateString(request,'jql','project = PROJECT ORDER BY key');
CkJsonObject_UpdateInt(request,'maxResults',50);
CkJsonObject_UpdateString(request,'fields[0]','summary');
CkJsonObject_UpdateString(request,'fields[1]','status');
CkJsonObject_UpdateString(request,'fields[2]','assignee');
previousToken := '';
nextToken := '';
more := True;
while (more = True) do
begin
CkStringBuilder_SetString(url,baseUrl);
CkStringBuilder_Append(url,'/rest/api/3/search/jql');
success := CkHttp_HttpJson(http,'POST',CkStringBuilder__getAsString(url),request,'application/json',resp);
if (CkHttpResponse_getStatusCode(resp) = 0) then
begin
Memo1.Lines.Add('No HTTP response was received. Check connectivity and TLS settings.');
Exit;
end;
if ((success <> True) or (CkHttpResponse_getStatusCode(resp) < 200) or (CkHttpResponse_getStatusCode(resp) >= 300)) then
begin
Memo1.Lines.Add('Request failed. HTTP ' + IntToStr(CkHttpResponse_getStatusCode(resp)));
if (CkHttpResponse_getStatusCode(resp) = 429) then
begin
Memo1.Lines.Add('Rate limited. Retry-After: ' + CkHttpResponse__getHeaderField(resp,'Retry-After'));
end;
// Inspect this response locally; it can contain private Jira data.
Memo1.Lines.Add(CkHttpResponse__bodyStr(resp));
Exit;
end;
success := CkJsonObject_Load(reply,CkHttpResponse__bodyStr(resp));
if (success <> True) then
begin
Memo1.Lines.Add('Expected a JSON object in the response.');
Exit;
end;
if (CkJsonObject_JsonTypeOf(reply,'issues') <> 4) then
begin
Memo1.Lines.Add('Expected an array: issues');
Exit;
end;
count := CkJsonObject_SizeOfArray(reply,'issues');
i := 0;
while (i < count) do
begin
CkJsonObject_putI(reply,i);
Memo1.Lines.Add(CkJsonObject__stringOf(reply,'issues[i].key') + ' ' + CkJsonObject__stringOf(reply,'issues[i].fields.summary') + ' ' + CkJsonObject__stringOf(reply,'issues[i].fields.status.name'));
if (CkJsonObject_IsNullOf(reply,'issues[i].fields.assignee') <> True) then
begin
Memo1.Lines.Add('Assignee: ' + CkJsonObject__stringOf(reply,'issues[i].fields.assignee.displayName'));
end;
i := i + 1;
end;
more := (CkJsonObject_BoolOf(reply,'isLast') <> True);
if (more = True) then
begin
if ((CkJsonObject_JsonTypeOf(reply,'nextPageToken') <> 1) or (CkJsonObject_StringOfEquals(reply,'nextPageToken','',True) = True)) then
begin
Memo1.Lines.Add('Missing value: nextPageToken');
Exit;
end;
nextToken := CkJsonObject__stringOf(reply,'nextPageToken');
if (nextToken = previousToken) then
begin
Memo1.Lines.Add('Repeated pagination token; stopping.');
Exit;
end;
previousToken := nextToken;
CkJsonObject_UpdateString(request,'nextPageToken',nextToken);
end;
end;
CkHttp_Dispose(http);
CkStringBuilder_Dispose(url);
CkHttpResponse_Dispose(resp);
CkJsonObject_Dispose(reply);
CkJsonObject_Dispose(request);