Retrieving User Profile info via Jira Cloud Automation
Asked by admin-nwalter:

My main goal is to be able to retrieve the information that is displayed on the user profile in Jira and apply those values within a Jira ticket, so when a ticket is created, this info is auto-populated in assigned custom fields. However, despite our Jira Cloud being synced with AzureAD, this info is not retrievable through automation. An alternative found way is through API.

I have created an Automation that basically does the below:

When: Issue is created

Then: Create Variable

* - Variable name: ReporterEmail
* - SmartValue: {{reporter.emailAddress}}

AND: Send Web Request

* - HTTP Method: POST
* - Web Request Body: Custom Data
* - Custom Data: Clientcredentialsandsecret
* - Header:
  * Key: Content-Type / Value: application/x-www-form-urlencoded

AND: Create variable

* - Variable name: AccessTokenTest
* - Smart Value: {{webhookResponse.body.access_token}}

AND: Send Web Request

* - Web Request URL: <https://graph.microsoft.com/v1.0/users/{{ReporterEmail>}}
* - HTTP Method: GET
* - Web Request Body: Empty
* - Header:
  * Key: Authorization / Value: Bearer {{AccessTokenTest}}
  * Content-Type: application/json

AND: Add value to the audit log.

* - Log message: {{webhookResponse.body}}

AND: Edit issue - Jobtitletest: {{webhookResponse.body.jobTitle}}

The automation runs successfull, but unfortunately it populates the customfield with literally the value "{{webhookResponse.body.jobTitle}}". The expected result was that it would retrieve the jobtitle from the webhook's response body, but it didn't. How can I achieve this? Again to reiterate, my goal is to map the user info that you can see in the User Profile within Jira, to custom fields within a ticket, every time a ticket gets created within the ITSD project. I do not want to use third party apps of any kind because we don't have the budget for that. Please help and apologies in advance if I didn't explain properly.


Answers:
author: Bill Sheboy
body: Hi [@admin-nwalter](/t5/user/viewprofilepage/user-id/4668680)

As you are showing a manually typed in version of your rule, versus images of the rule and audit log, the community will need to guess a bit in order to help...

In the rule you describe, you write this value to the audit log in the second-to-last step:
> AND: Add value to the audit log.
>
> - Log message: {{webhookResponse.body}}

Does that write to the audit log contain what you expect?

Next, you state that Edit Issue action at the end of the rule, apparently of the field Jobtitletest, is writing the smart value expression rather than the *value of that expression*. Have you confirmed that smart value expression is correct and has no typographical errors?

Kind regards,  
Bill

comments: author: admin-nwalter
body: Hello [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) ,

Apologies for that. I didn't think the screenshot would contain sufficient info or would be sufficient:

![Screenshot_997.png](https://community.atlassian.com/t5/image/serverpage/image-id/331389i05CB81CA0AB6667D/image-size/large?v=v2&px=999 "Screenshot_997.png")

To answer your question, the second to last option (adding value to the audit log) does bring a result, but actually shows the Access Token instead of what I expected.

Regarding your last question, i had found documentation that this was possible, but I am not able to find it any more. Not sure if this idea was a fever dream or exhaustion.


author: Bill Sheboy
body: Thanks for that information to confirm the rule structure.

The Issue Created trigger can fire so quickly that some information may not be available to the rule yet. I recommend adding the Re-fetch Issue immediately after the trigger to prevent any timing problems with it.

Next, do each of your Send Web Request actions have the option enabled to wait until the response occurs? It is this checkbox: "Delay execution of subsequent rule actions until we've received a response..."

Finally, I wonder if {{webhookResponse.body.jobTitle}} in your Edit Issue action is not parsing correctly, particularly if the rule is not recognizing it as well-formed JSON. That can be confirmed by also writing just that expression to the log. The workaround may be to use the match() function with a regular expression to parse the body: <https://support.atlassian.com/cloud-automation/docs/jira-smart-values-text-fields/#match-->


author: admin-nwalter
body: Dear Bill,

I think the re-fetch issue did trick combined with the "Delay execution" which was not active for the second Web Request. The logged actions now display the right options and the field is populated correctly now.

This opens up a lot of possibilities for now. Much obliged!


Tags: cloud

jira-service-management

jira-service-management-cloud