Sample code for 30+ languages & platforms
Lua Requires Chilkat v11.0.0+

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 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 request = chilkat.JsonObject.new()
-- Bound the query to a project. Adapt the JQL to your permissions and needs.
request:update_string("jql", "project = PROJECT ORDER BY key")
request:update_int("maxResults", 50)
request:update_string("fields[0]", "summary")
request:update_string("fields[1]", "status")
request:update_string("fields[2]", "assignee")
local previousToken = ""
local nextToken = ""
local more = true
while more do
    url:set_string(baseUrl)
    url:append("/rest/api/3/search/jql")
    success = http:http_json("POST", url:get_as_string(), request, "application/json", 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 count = reply:size_of_array("issues")
    local i = 0
    while i < count do
        reply.i = i
        print(reply:string_of("issues[i].key") .. "  " .. reply:string_of("issues[i].fields.summary") .. "  " .. reply:string_of("issues[i].fields.status.name"))
        if not reply:is_null_of("issues[i].fields.assignee") then
            print("Assignee: " .. reply:string_of("issues[i].fields.assignee.displayName"))
        end

        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
        request:update_string("nextPageToken", nextToken)
    end
end