How to create Asset objects via REST API based on different attribute type

Still need help?

The Atlassian Community is here for you.

Ask the community


Platform Notice: Cloud Only - This article only applies to Atlassian products on the cloud platform.

Summary


There is a scenario where the admin needs to create an Asset object via REST API. In Assets Cloud REST API documentation, have a list of APIs available. However, it didn't give the example of a JSON template for a certain scenarios. For this article, I will give you the list of JSON templates to create a new object based on each attribute type. Using the same JSON template you can use it to update Asset object using REST API too.

Environment

JSM Assets

Scenario

Admin needs to create a new object using REST API, and the object type has multiple attribute type.

Solution

Follow the steps by steps to create a new object using REST API :-

  1. Generate an API token for your account to execute the REST API using Basic Authentication :-
    1. Go to https://id.atlassian.com/manage/api-tokens
    2. Click Create API Token 
    3. Set a Label and click Create 
    4. Save the Token somewhere safe to use it for later.
  2. Get the workspace id  for your site :-
    1. Run the API below :- 

      https://<JSM Premium Site Name>.atlassian.net/rest/servicedeskapi/insight/workspace
    2. From the response, save the workspace id 
  3. Then, use the POST object API to create the new object. The API is as below , make sure to update the workspace ID:- 

    POST https://api.atlassian.com/jsm/insight/workspace/{workspaceId}/v1/object/create
  4. Now to structure the JSON template, the basic template is as below:- 

    {
      "objectTypeId": "250",
      "attributes": [
        {
          "objectTypeAttributeId": "2797",
          "objectAttributeValues": [
            {
              "value": "Test"
            }
          ]
        },
        {
          "objectTypeAttributeId": "2807",
          "objectAttributeValues": [
            {
              "value": "Testing"
            }
          ]
        }
      ]
    }

    ObjectTypeID : You can get it from the Object Type configuration page. For example as per the screenshot below:-

    ObjectTypeAttributeID : You can get it from the Object Type attribute configuration page. For example as per the screenshot below:-
  5. Below is the detailed template for each attribute :-
Attribute TypeNotesExample
TextThe value just needs to be the expected text.{
      "objectTypeAttributeId": "2797",
      "objectAttributeValues": [
        {
          "value": "Test"
        }
      ]
    }
BooleanThe value can be either true or false.{
      "objectTypeAttributeId": "2800",
      "objectAttributeValues": [
        {
          "value": "true"
        }
      ]
    }
IntegerThe value must be an exact number.{
      "objectTypeAttributeId": "2801",
      "objectAttributeValues": [
        {
          "value": "123"
        }
      ]
    }
FloatThe value must be a floating number.{
      "objectTypeAttributeId": "2802",
      "objectAttributeValues": [
        {
          "value": "123.0"
        }
      ]
    }
DateThe value format is YYYY-MM-DD {
      "objectTypeAttributeId": "2803",
      "objectAttributeValues": [
        {
          "value": "2022-08-09"
        }
      ]
    }
Date and TimeThe value format is YYYY-MM-DDTHH:mm:ss.sssZ {
      "objectTypeAttributeId": "2804",
      "objectAttributeValues": [
        {
          "value": "2022-08-10T13:00:00.000+10:00"
        }
      ]
    }
URLThe value must start with HTTP:// or HTTPS://{
      "objectTypeAttributeId": "2805",
      "objectAttributeValues": [
        {
          "value": "https://www.google.com"
        }
      ]
    }
EmailThe value must be a valid email format{
      "objectTypeAttributeId": "2806",
      "objectAttributeValues": [
        {
          "value": "atiqah@gmail.com"
        }
      ]
    }
Text AreaThe value just needs to be the expected text.{
      "objectTypeAttributeId": "2807",
      "objectAttributeValues": [
        {
          "value": "This is a long text"
        }
      ]
    }
SelectThe value must be the selection value name. This is the example for single value.{
      "objectTypeAttributeId": "2808",
      "objectAttributeValues": [
        {
          "value": "one"
        }
      ]
    }
The value must be the selection value name. This is the example for multi-value.{
      "objectTypeAttributeId": "2808",
      "objectAttributeValues": [
        {
          "value": "one"
        },
        {
          "value": "two"
        }
      ]
    }
IP AddressThe value must represent IP Addresses (IPv4) . This is the example for single value.{
      "objectTypeAttributeId": "2809",
      "objectAttributeValues": [
        {
          "value": "10.11.11.11"
        }
      ]
    }
Reference ObjectThe value must be the reference object key. This is the example for single value.{
      "objectTypeAttributeId": "2811",
      "objectAttributeValues": [
        {
          "value": "AP-76"
        }
      ]
    }
The value must be the reference object key. This is the example for multi-value.{
      "objectTypeAttributeId": "2811",
      "objectAttributeValues": [
        {
          "value": "AP-24"
        },
        {
          "value": "AP-76"
        }
      ]
    }
GroupThe value must be the group name. This example is for a single value.{
      "objectTypeAttributeId": "2812",
      "objectAttributeValues": [
        {
          "value": "administrators"
        }
      ]
    }
The value must be the group name. This example is for a multi value.{
      "objectTypeAttributeId": "2812",
      "objectAttributeValues": [
        {
          "value": "administrators"
        },
        {
          "value": "atlassian-addons-admin"
        }
      ]
    }
UserThe value must be the user Atlassian Account id. This example is for a single value.

{
      "objectTypeAttributeId": "2810",
      "objectAttributeValues": [
        {
          "value": "557057:1a8aeee5-40e9-413a-9f4e-2f074f09644a"
        }
      ]
    }

The value must be the user Atlassian Account id. This example is for a multi-value.{
      "objectTypeAttributeId": "2810",
      "objectAttributeValues": [
        {
          "value": "557057:1a8aeee5-40e9-413a-9f4e-2f074f09644a"
        },
        {
          "value": "557058:13a8c36c-79e5-44d7-8a6a-d985370a8c91"
        }
      ]
    }


Tips : For easier way to get the correct JSON template for your REST API , try to create or update the object from the UI. While doing it , open the Developer Tool > Network  and look for the create request and click Payload . It will look like as per the screenshot below :-

Click View Source  for the raw data :-

For Postman users , the request will look as per screenshot below :-


Last modified on Oct 25, 2022

Was this helpful?

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