Going Stellar

Home/Atlassian REST API reference

Jira and Confluence Cloud REST API

Search Jira work items with JQL using the REST API

JQL search is /rest/api/3/search/jql, as POST with a JSON body or GET with query parameters. It pages with nextPageToken instead of startAt, has no total, and returns only the work item id unless fields lists more. The old /rest/api/3/search is gone and answers 410.

Endpoints

MethodPathWhat it does
POST/rest/api/3/search/jqlSearches with a JSON body.
GET/rest/api/3/search/jqlSearches with query parameters.

Examples

POST /rest/api/3/search/jql

Asks for one work item per page with summary and status. The response carries nextPageToken and isLast false.

curl

curl -X POST \
  -u "you@example.com:$ATLASSIAN_API_TOKEN" \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  --data '{
  "jql": "project = WEB AND summary ~ \"REST API reference test\" ORDER BY created ASC",
  "fields": [
    "summary",
    "status"
  ],
  "maxResults": 1
}' \
  'https://your-domain.atlassian.net/rest/api/3/search/jql'

Python (requests)

import os
import requests

EMAIL = "you@example.com"
r = requests.post(
    'https://your-domain.atlassian.net/rest/api/3/search/jql',
    auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
    headers={'Accept': 'application/json'},
    json={'jql': 'project = WEB AND summary ~ "REST API reference test" ORDER BY created ASC',
          'fields': ['summary', 'status'],
          'maxResults': 1},
)
print(r.status_code, r.text)

Response: HTTP 200

{
 "issues": [
  {
   "key": "WEB-55",
   "fields": {
    "summary": "REST API reference test issue",
    "status": {
     "name": "In Progress"
    }
   }
  }
 ],
 "nextPageToken": "CkhjcmVhdGVkJmNyZWF0ZWQmT1JERVJfQVNDI0xvbmcmTVRjNU5UazNNek0xTlRZNU9BPT0lU3RyaW5nJlYwVkMlSW50Jk5UVT0QARiRle_CojQiSnByb2plY3QgPSBXRUIgQU5EIHN1bW1hcnkgfiAiUkVTVCBBUEkgcmVmZXJlbmNlIHRlc3QiIE9SREVSIEJZIGNyZWF0ZWQgQVNDKgJbXQ==",
 "isLast": false
}

Response headers

X-Ratelimit-Limit: 200

Sent to Atlassian Cloud on .

POST /rest/api/3/search/jql

Sends the same query again with the token. The last page has isLast true and no token.

curl

curl -X POST \
  -u "you@example.com:$ATLASSIAN_API_TOKEN" \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  --data '{
  "jql": "project = WEB AND summary ~ \"REST API reference test\" ORDER BY created ASC",
  "fields": [
    "summary",
    "status"
  ],
  "maxResults": 1,
  "nextPageToken": "{nextPageToken}"
}' \
  'https://your-domain.atlassian.net/rest/api/3/search/jql'

Python (requests)

import os
import requests

EMAIL = "you@example.com"
r = requests.post(
    'https://your-domain.atlassian.net/rest/api/3/search/jql',
    auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
    headers={'Accept': 'application/json'},
    json={'jql': 'project = WEB AND summary ~ "REST API reference test" ORDER BY created ASC',
          'fields': ['summary', 'status'],
          'maxResults': 1,
          'nextPageToken': '{nextPageToken}'},
)
print(r.status_code, r.text)

Response: HTTP 200

{
 "issues": [
  {
   "key": "WEB-56",
   "fields": {
    "summary": "REST API reference test issue2 - delete"
   }
  }
 ],
 "isLast": true
}

Sent to Atlassian Cloud on .

GET /rest/api/3/search/jql

The GET form, with fields and maxResults as query parameters.

curl

curl -G \
  -u "you@example.com:$ATLASSIAN_API_TOKEN" \
  -H 'Accept: application/json' \
  --data-urlencode 'jql=project = WEB AND summary ~ "REST API reference test" ORDER BY created ASC' \
  --data-urlencode 'fields=summary' \
  --data-urlencode 'maxResults=2' \
  'https://your-domain.atlassian.net/rest/api/3/search/jql'

Python (requests)

import os
import requests

EMAIL = "you@example.com"
r = requests.get(
    'https://your-domain.atlassian.net/rest/api/3/search/jql',
    auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
    headers={'Accept': 'application/json'},
    params={'jql': 'project = WEB AND summary ~ "REST API reference test" ORDER BY created ASC',
 'fields': 'summary',
 'maxResults': '2'},
)
print(r.status_code, r.text)

Response: HTTP 200

{
 "issues": [
  {
   "key": "WEB-55",
   "fields": {
    "summary": "REST API reference test issue"
   }
  },
  {
   "key": "WEB-56",
   "fields": {
    "summary": "REST API reference test issue2 - delete"
   }
  }
 ],
 "isLast": true
}

Response headers

X-Ratelimit-Limit: 350

Sent to Atlassian Cloud on .

GET /rest/api/3/search/jql

Leaves fields out. Each work item comes back with its id only.

curl

curl -G \
  -u "you@example.com:$ATLASSIAN_API_TOKEN" \
  -H 'Accept: application/json' \
  --data-urlencode 'jql=project = WEB AND summary ~ "REST API reference test" ORDER BY created ASC' \
  --data-urlencode 'maxResults=1' \
  'https://your-domain.atlassian.net/rest/api/3/search/jql'

Python (requests)

import os
import requests

EMAIL = "you@example.com"
r = requests.get(
    'https://your-domain.atlassian.net/rest/api/3/search/jql',
    auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
    headers={'Accept': 'application/json'},
    params={'jql': 'project = WEB AND summary ~ "REST API reference test" ORDER BY created ASC',
 'maxResults': '1'},
)
print(r.status_code, r.text)

Response: HTTP 200

{
 "issues": [
  {
   "id": "10766"
  }
 ],
 "isLast": false
}

Sent to Atlassian Cloud on .

POST /rest/api/3/search/jql

A query that ends after the operator. The message names the position problem.

curl

curl -X POST \
  -u "you@example.com:$ATLASSIAN_API_TOKEN" \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  --data '{
  "jql": "project = WEB AND status = ",
  "maxResults": 1
}' \
  'https://your-domain.atlassian.net/rest/api/3/search/jql'

Python (requests)

import os
import requests

EMAIL = "you@example.com"
r = requests.post(
    'https://your-domain.atlassian.net/rest/api/3/search/jql',
    auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
    headers={'Accept': 'application/json'},
    json={'jql': 'project = WEB AND status = ', 'maxResults': 1},
)
print(r.status_code, r.text)

Response: HTTP 400

{
 "errorMessages": [
  "Error in JQL Query: Expecting either a value, list or function before the end of the query."
 ],
 "errors": {}
}

Sent to Atlassian Cloud on .

POST /rest/api/3/search/jql

A query with only an ORDER BY. It has no search restriction and is refused.

curl

curl -X POST \
  -u "you@example.com:$ATLASSIAN_API_TOKEN" \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  --data '{
  "jql": "order by created DESC",
  "maxResults": 1,
  "fields": [
    "summary"
  ]
}' \
  'https://your-domain.atlassian.net/rest/api/3/search/jql'

Python (requests)

import os
import requests

EMAIL = "you@example.com"
r = requests.post(
    'https://your-domain.atlassian.net/rest/api/3/search/jql',
    auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
    headers={'Accept': 'application/json'},
    json={'jql': 'order by created DESC', 'maxResults': 1, 'fields': ['summary']},
)
print(r.status_code, r.text)

Response: HTTP 400

{
 "errorMessages": [
  "Unbounded JQL queries are not allowed here. Please add a search restriction to your query."
 ],
 "errors": {}
}

Sent to Atlassian Cloud on .

GET /rest/api/3/search

The previous GET /rest/api/3/search. It answers 410 and names the replacement.

curl

curl -G \
  -u "you@example.com:$ATLASSIAN_API_TOKEN" \
  -H 'Accept: application/json' \
  --data-urlencode 'jql=project = WEB' \
  --data-urlencode 'maxResults=1' \
  'https://your-domain.atlassian.net/rest/api/3/search'

Python (requests)

import os
import requests

EMAIL = "you@example.com"
r = requests.get(
    'https://your-domain.atlassian.net/rest/api/3/search',
    auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
    headers={'Accept': 'application/json'},
    params={'jql': 'project = WEB', 'maxResults': '1'},
)
print(r.status_code, r.text)

Response: HTTP 410

{
 "errorMessages": [
  "The requested API has been removed. Please migrate to the /rest/api/3/search/jql API. A full migration guideline is available at https://developer.atlassian.com/changelog/#CHANGE-2046"
 ],
 "errors": {}
}

Sent to Atlassian Cloud on .

How it behaves

  • The response has no total. Paging is done with nextPageToken, and the last page leaves that key out and sets isLast to true.
  • Without fields, each issue object held only id. The spec states the default is id.
  • fields=*all returned 51 fields for one work item, including customfield_ entries, while fields=summary returned only summary.
  • POST /rest/api/2/search/jql worked as well and gave the same shape, with self links under /rest/api/2/.
  • A JQL syntax error and an unbounded query both gave 400 with the reason in errorMessages. The old GET /rest/api/3/search and /rest/api/2/search gave 410.

Pitfalls

  • Loop until isLast is true. A short page does not mean the end, because maxResults can be lowered when many fields are requested.
  • Send the same jql, fields and maxResults with every nextPageToken. The follow-up run repeated all three.
  • Add a restriction such as project = KEY before ORDER BY. A bare order by is a 400.
  • Name the fields you need. Asking for *all makes pages heavy, and the spec says the page size is largest when only id or key is requested.

Questions and answers

Why is there no total in the search response?

The enhanced search pages with nextPageToken and does not count. POST /rest/api/3/search/approximate-count gives an estimate.

Why do I only get ids back?

fields defaults to id. List the fields you want, or use *navigable or *all.

Sources

  1. The Jira Cloud platform REST API v3 (Atlassian Developer)
  2. Search for issues using JQL enhanced search (POST) (Jira REST API v3)

Markdown version · All REST API pages