Update Issues based on JQL with REST API in Jira Data Center
Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.
Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
This article proposes a solution to update Issues that match a JQL using Jira Data Center's REST API.
Solution
The solution is to first search for the issues and then, for each of them, call the update. This would result in "1 + N" REST API calls, N being the number of issues returned by the JQL.
Perform the JQL search through POST or GET to /rest/api/2/search (Server/DC API reference)
Parse the result to you get only the issue keys returned
For each issue key, call the update endpoint through PUT to /rest/api/2/issue/{issueIdOrKey} (Server/DC API reference)
Examples in shell script
Search issues with the JQL
$ curl -u admin:admin -X POST localhost:50813/rest/api/2/search -H "Content-Type: application/json" -d '{"jql":"updated > -1d","fields":[""]}' -s | jq > jql-output.txt
{ "expand": "schema,names", "startAt": 0, "maxResults": 50, "total": 10, "issues": [ { "expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields", "id": "10108", "self": "http://localhost:50813/rest/api/2/issue/10108", "key": "SC1-10" }, { "expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields", "id": "10107", "self": "http://localhost:50813/rest/api/2/issue/10107", "key": "SC1-9" }, { "expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields", "id": "10106", "self": "http://localhost:50813/rest/api/2/issue/10106", "key": "SC1-8" } ] }
Parse the json output
$ cat jql-output.txt | grep '"key"' | egrep -o ': ".*?"' | cut -c3- | sed 's/"//g' > keys.txt
SC1-10 SC1-9 SC1-8
For each issue key, update the issue
$ for issue in $(cat keys.txt); do curl -u admin:admin -X PUT localhost:50813/rest/api/2/issue/$issue -H "Content-Type: application/json" -d '{"fields":{"customfield_10400":"Sample text for a Text Field!"}}'; done;
Alternative one-line example
$ for issue in \ $(curl -u admin:admin -X POST localhost:50813/rest/api/2/search -H "Content-Type: application/json" -d '{"jql":"updated > -1d","fields":[""]}' -s | jq | grep '"key"' | egrep -o ': ".*?"' | cut -c3- | sed 's/"//g');\ do curl -u admin:admin -X PUT localhost:50813/rest/api/2/issue/$issue -H "Content-Type: application/json" -d '{"fields":{"customfield_10400":"Sample text for a Text Field!"}}';\ done;
For all command examples above:
Replace this | For this |
admin:admin | Valid username:password (with browse and edit permissions in the projects) |
localhost:50813 | Jira's base URL |
updated > -1d | The desired JQL |
customfield_10400 | The customfield to update |
For more examples on how to edit issues through the REST API, like updating multiple fields, check the Server/DC REST API edit examples!
Was this helpful?