Run JQL search query using Jira Cloud REST API
プラットフォームについて: Cloud のみ - この記事は クラウド プラットフォームのアトラシアン製品に適用されます。
要約
You can use Jira Cloud's REST API to return work items based on a JQL search query.
In turn, we can use additional methods to return Jira work items using the API, including:
- Performing a cURL request
- Creating an automation rule to Send a web request
In all cases, we'll use the Search for issues using JQL (GET) API endpoint. As the JQL query is a request parameter for this resource, it must be URL-encoded in order to work correctly.
Encode the JQL query
There are two ways to encode a JQL query to make it URL-compatible.
Option 1: Run JQL in Jira and copy from address bar
- In Jira, select Search > View all issues
- Write a JQL query and select the
Search icon
- In your browser's address bar, the JQL query will be encoded following
jql=
- In your browser's address bar, the JQL query will be encoded following
- Copy the text following the "=" character for use in the API
Option 2: Use URL encoding smart value in Jira Automation
Jira Automation supports the URL Encoding Smart Value in automation rules that you create. You can input your JQL query as you would in Jira search to get the proper encoded value returned.
例:
{{#urlEncode}}project = SUP and created > -5d{{/}}
For more details, please refer to our documentation on Smart Values in Jira Automation.
JQL API search with cURL
This operation requires an API token. Please refer to Manage API tokens for your Atlassian account.
This cURL command returns work items created in the last 7 days for the "OP" project.
curl --request GET \
--url 'https://yoursitename.atlassian.net/rest/api/3/search?maxResults=10000&jql%3Dproject%3DOP%20and%20created%20%3E%3D%20-7d' \
--user 'youremail@mail.com:yourapitoken' \
--header 'Accept: application/json'
JQL API search with Postman
This operation requires an API token. Please refer to Manage API tokens for your Atlassian account.
The screenshot below provides an example of project OP work items created within the last 5 days.
JQL API search from Jira automation
The following examples show automation rules that use the Send web request action. For more details on how to build this type of rule please check Automation for Jira - Send web request using Jira REST API.
Automation rule using a manually encoded JQL query
https://yoursitename.atlassian.net/rest/api/3/search?fields=key&maxResults=500&jql=project%3DOG%20and%20created%3E%3D%20-5d
Automation rule using a JQL query encoded by the URL encoding smart value
https://yoursitename.atlassian.net/rest/api/3/search?fields=key&maxResults=500&jql={{#urlEncode}}project=OG and created>= -5d{{/}}
Web Response Smart Values for adding values to the Audit Log
Jira Issue JSON URL: {{webResponse.body.issues.self}} Jira Issue Keys: {{webResponse.body.issues.key}}
- Result from both automation rules:
- Result from both automation rules: