Add user accountId to a Asset objects

This tutorial describes how to add accountId to a asset object from Jira users.

 

Starting point

  1. Navigate to Integrations and click new Integration and name it something useful.

  2. 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

  3. The token will be used later on in the web actions.

 

 

 

Step 1. Get the the objects that will be updated with accountId.

  1. Create a new Action, name it Get Assets User Object without accountId

  2. Select Method POST

  3. Enter URL https://api.atlassian.com/jsm/assets/workspace/{{workspaceId}}/v1/object/aql

  4. 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" }
  5. Select Variables tab and then click Javascript variable

  6. Enter the name workspaceId

  7. Paste the workspace id into the value

  8. Click Save.


Step 2. Lookup the accountId.

  1. Create a new Action called lookup account id from email

  2. Select method GET

  3. Enter url {{baseUrl}}/rest/api/3/user/search?query={{email}}

  4. Select the PAT token or the build in Atlassian Authentication token

  5. Click on Advanced tab

  6. Add a Iteration value: $.values

  7. Click Save

 


Step 3. update account id on asset

  1. Create a new Action

  2. Select method POST

  3. Enter url https://api.atlassian.com/jsm/assets/workspace/{{workspaceId}}/v1/object/{{id}}

  4. Add the body

    { "attributes": [ { "objectTypeAttributeId": "1653", "objectAttributeValues": [ { "value": "{{accountId}}" } ] } ] }
  5. Select the PAT token as Authentication

  6. Select Variables tab

  7. Add a json path
    accountId with value

     

  8. Click save

 

Step 4. Schedule the execution

  1. Click on Triggers

  2. Select Schedule Trigger

  3. 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.

Â