Creating and linking an Asset object using Automation for Jira via REST API

Still need help?

The Atlassian Community is here for you.

Ask the community

Platform Notice: Data Center - This article applies to Atlassian products on the Data Center platform.

Note that this knowledge base article was created for the Data Center version of the product. Data Center knowledge base articles 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

Purpose

  • Currently, the integration between Automation for Jira and Assets objects is limited in the Jira Data Center, it's not possible to use Actions to create Assets objects: JIRAAUTOSERVER-869 - Getting issue details... STATUS JIRAAUTOSERVER-464 - Getting issue details... STATUS

Requirements 

  • Automation For Jira
  • Assets plugin
  • An Assets custom field configured for linking the object with the Jira issue - Default Assets custom field

Solution

This documentation described how to use Automation for Jira (bundled with Jira 9.0+) to create and link Assets objects in Jira issues using REST API from Assets: Assets REST API documentation

Step

1.

Create a trigger: In this example, "Field value changed" is used to monitor the "Labels" field for "All issue operations", but other triggers can be used depending on your needs: 

2. 

Create an Issue fields condition: In order to trigger the automation, create an "Issue Fields Condition". For example, execute the automation for all Jira issues with the "assets_create_object" added:

3. 

Create a Send web request action: To create an object in Assets, we'll use the "Send Web Request" action to perform a POST in the create object REST API:

  1. Webhook URL: 

    <JIRA_BASEURL>/rest/assets/1.0/object/create
  2. Headers: For creating the <TOKEN> use: Using Personal Access Tokens

    Headers
    Content-Typeapplication/json
    AuthorizationBearer <TOKEN>
  3. HTTP method: POST
  4. Webhook body: Custom data
  5. Wait for response:  Delay execution of subsequent rule actions until we've received a response for this webhook
  6. Custom data: We will use this field as a payload for custom fields that will be used to attribute assets using smart values. For example, two custom text fields are used: "Device Name" and "Vendor Name". The number of custom fields can change, depending on the number of attributes we would like to fill.

    {
        "objectTypeId": 24,
        "attributes": [
            {
                "objectTypeAttributeId": 154,
                "objectAttributeValues": [
                    {
                        "value": "{{Device Name}}"
                    }
                ]
            },
                  {
                "objectTypeAttributeId": 217,
                "objectAttributeValues": [
                    {
                        "value": "{{Vendor Name}}"
                    }
                ]
            }
        ]
    }

      To match your configuration, you'll have to replace the values for objectTypeId and objectTypeAttributeId. - Assets (formerly Insight): How to get the IDs of object schema, object type and object from the Jira User Interface

4.

Create an Edit issue action: Select the Assets custom field which will return the object created

Additional fields: Add the JSON (webhook response smart value will be used to get the object key created) 

{
    "update" : {
        "Host" : [{"add": [{"key" : "{{webhookResponse.body.objectKey}}"}]}]
    }
}

Replace the Host custom field with your Assets custom field - Assets with Jira REST API 


Last modified on Oct 24, 2024

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.