Automate Issue Field Updates Using Jira Cloud REST API
Platform Notice: Cloud Only - This article only applies to Atlassian products on the cloud platform.
Summary
Learn how to use Jira REST API with Automation to make advanced changes to Jira issues. This is particularly useful when issues are created from third-party actions, like Slack or email. We'll show you how to set user fields, such as assignee or reporter, based on data in the issue's description or summary.
Solution
Using Jira REST API to Retrieve User Account ID
To assign an issue to a user, you'll need to retrieve their Account ID using the Jira REST API. Start by Manage API tokens for your Atlassian account. If you're new to Jira REST APIs, check out The Jira Cloud platform REST API to understand how they work.
Building the automation rule
Trigger
Let's say issues are getting created in Jira but are missing important Jira fields such as assignee or reporter. Let's go to our project and select Project Settings > Automation. Let's create a rule and pick the Issue Created trigger.
Creating a variable
However, the information that is supposed to be set in the assignee or reporter fields (or just any other user picker fields) is stored in the description field. This information may be either the name or email address of the user we need to set. In order to retrieve this information, we can use the match function. For more information, please see Extract content out of description and summary with regex and Automation.
Let's add the first component to the rule, and we're going to use the Create variable action. Type any name for your variable, and we use the following regex smart value to match a user's email from the issue's description:
{{issue.description.match(".*Email: (\S+).*")}}
In our example, we'll call the variable matchedEmailAddress.
Send a web request
Now that the email address is available as a smart variable and we can easily access it, it's time to get the user's Account ID. As mentioned above, we can use the API to search for users by name or email because this is what the REST API supports. In order to send a web request via Automation, first, you need to add your API token as the Authorization header. For more information on how to do that, please read this Community post.
When this is done, we can now easily send your web request. As the web request URL, we will use the following address with smart value syntax:
http://<jira_instance>/rest/api/3/user/search?query={{matchedEmailAddress.urlEncode}}
The HTTP method we need is GET. Other things to check before you proceed:
Make sure to include the entire instance URL, for example: my-instance.atlassian.net.
Also, if you called your variable differently, make sure to change it as well.
Don't forget to add the urlEncode parameter to your variable.
Finally, don't forget to tick the option "Delay execution of subsequent rule actions until we've received a response for this web request". We want to make sure the request is completed before we proceed to the next step in the automation.
Update a field
If our web request succeeded, we should have the Account ID we needed. With the Account ID, we can set all user picker fields correctly in Jira. In order to do that, add the Edit issue action, and as the value for your field, use the following smart value:
{{webResponse.body.first.accountId}}
You can try to test the rule now. If everything went well, you should see it update the user picker field of your choice with the right user. If the rule fails, refer to debug automation rules for smart values.
Was this helpful?