Home/Atlassian REST API reference
Jira and Confluence Cloud REST API
Paginate Jira JQL search with nextPageToken
The JQL search endpoint does not take startAt. The first request has no token, each page returns nextPageToken while more results exist, and the last page has isLast true and no token. The response has no total, so use the approximate count endpoint for a number. The default is also surprising: without fields only the id of each work item comes back.
Endpoints
| Method | Path | What it does |
|---|---|---|
POST | /rest/api/3/search/jql | Searches with a JSON body that carries jql, fields, maxResults and nextPageToken. |
GET | /rest/api/3/search/jql | Same search with query parameters. |
POST | /rest/api/3/search/approximate-count | Returns an approximate number of matches. |
Examples
POST /rest/api/3/search/jql
First page of size 1: the work item and a nextPageToken, with 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": [
{
"id": "10766",
"key": "WEB-55",
"fields": {
"summary": "REST API reference test issue"
}
}
],
"nextPageToken": "CkhjcmVhdGVkJmNyZWF0ZWQmT1JERVJfQVNDI0xvbmcmTVRjNU5UazNNek0xTlRZNU9BPT0lU3RyaW5nJlYwVkMlSW50Jk5UVT0QARiRle_CojQiSnByb2plY3QgPSBXRUIgQU5EIHN1bW1hcnkgfiAiUkVTVCBBUEkgcmVmZXJlbmNlIHRlc3QiIE9SREVSIEJZIGNyZWF0ZWQgQVNDKgJbXQ==",
"isLast": false
}Sent to Atlassian Cloud on .
POST /rest/api/3/search/jql
Second request: the same body plus the nextPageToken. The final 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": [
{
"id": "10767",
"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 returns both work items with isLast true when the page size is large enough.
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": [
{
"id": "10766",
"key": "WEB-55",
"fields": {
"summary": "REST API reference test issue"
}
},
{
"id": "10767",
"key": "WEB-56",
"fields": {
"summary": "REST API reference test issue2 - delete"
}
}
],
"isLast": true
}Sent to Atlassian Cloud on .
GET /rest/api/3/search/jql
Without fields, each issue holds only an id.
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"
}
],
"nextPageToken": "CkhjcmVhdGVkJmNyZWF0ZWQmT1JERVJfQVNDI0xvbmcmTVRjNU5UazNNek0xTlRZNU9BPT0lU3RyaW5nJlYwVkMlSW50Jk5UVT0QARjVqO_CojQiSnByb2plY3QgPSBXRUIgQU5EIHN1bW1hcnkgfiAiUkVTVCBBUEkgcmVmZXJlbmNlIHRlc3QiIE9SREVSIEJZIGNyZWF0ZWQgQVNDKgJbXQ==",
"isLast": false
}Sent to Atlassian Cloud on .
POST /rest/api/3/search/jql
A query with only ORDER BY is rejected.
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 .
POST /rest/api/3/search/approximate-count
Gets a count, since the search response has no total.
curl
curl -X POST \
-u "you@example.com:$ATLASSIAN_API_TOKEN" \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
--data '{
"jql": "project = WEB"
}' \
'https://your-domain.atlassian.net/rest/api/3/search/approximate-count'Python (requests)
import os
import requests
EMAIL = "you@example.com"
r = requests.post(
'https://your-domain.atlassian.net/rest/api/3/search/approximate-count',
auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
headers={'Accept': 'application/json'},
json={'jql': 'project = WEB'},
)
print(r.status_code, r.text)Response: HTTP 200
{
"count": 34
}Sent to Atlassian Cloud on .
How it behaves
- The first POST used maxResults 1 and returned one work item, a nextPageToken and isLast false.
- Sending the same body with nextPageToken set returned the second work item, isLast true and no nextPageToken key.
- GET /rest/api/3/search/jql without fields returned issues with only id, matching the default of id in the OpenAPI text.
- A JQL of only order by created DESC answered 400 with a message that unbounded JQL queries are not allowed and a search restriction is needed.
- The response has no total or startAt. The approximate count call returned count 34 for project = WEB.
Pitfalls
- Send the same jql, fields and maxResults with every token, as the two page run did.
- Treat nextPageToken as an opaque string and pass it back unchanged.
- Ask for fields explicitly. The default of id only differs from GET issue, which returns all fields.
- Per the OpenAPI text maxResults defaults to 50 and is capped at 5000 issues when only id or key is requested, and fewer when many fields are requested.
Questions and answers
Can I jump to page 5?
The reference lists no startAt parameter for this endpoint, so later pages are reached by following the tokens.
How do I get the total number of matches?
Call POST /rest/api/3/search/approximate-count with the same JQL. The name says approximate, so treat it that way.
Related
- Search with JQL
- Approximate count
- The removed /search endpoint
- startAt and maxResults
- expand, fields and properties parameters