Add user accountId to a Asset objects
This tutorial describes how to add accountId to a asset object from Jira users.
Â
Starting point
Navigate to Integrations and click new Integration and name it something useful.
To update assets you must create a PAT token in the Credentials sections see instructions here https://confluence.atlassian.com/enterprise/using-personal-access-tokens-1026032365.html
The token will be used later on in the web actions.
Â
Â
Â
Step 1. Get the the objects that will be updated with accountId.
Create a new Action, name it Get Assets User Object without accountId
Select Method POST
Enter URL https://api.atlassian.com/jsm/assets/workspace/{{workspaceId}}/v1/object/aql
Enter a Body that search for the object type you want to update and where the attribute AccountId is empty. Check the Assets module to find the id of the object type.
{ "qlQuery": "objectTypeId = 199 and AccountId IS empty" }
Select Variables tab and then click Javascript variable
Enter the name workspaceId
Paste the workspace id into the value
Click Save.
Step 2. Lookup the accountId.
Create a new Action called lookup account id from email
Select method GET
Enter url {{baseUrl}}/rest/api/3/user/search?query={{email}}
Select the PAT token or the build in Atlassian Authentication token
Click on Advanced tab
Add a Iteration value: $.values
Click Save
Â
Step 3. update account id on asset
Create a new Action
Select method POST
Enter url https://api.atlassian.com/jsm/assets/workspace/{{workspaceId}}/v1/object/{{id}}
Add the body
{ "attributes": [ { "objectTypeAttributeId": "1653", "objectAttributeValues": [ { "value": "{{accountId}}" } ] } ] }
Select the PAT token as Authentication
Select Variables tab
Add a json path
accountId with valueÂ
Click save
Â
Step 4. Schedule the execution
Click on Triggers
Select Schedule Trigger
Run it on a good interval like once per day
Summarize
The integration flow will run on an interval and the first action will get all user objects that does not have an accountId, then it will iterate over that list and find the accountId for the user and finally do a PUT operation to update the object with the accountId.
Â