Create Assets objects via REST API for various attribute types in Jira Cloud
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 the REST API.
Solution
The purpose of this documentation
In the Assets Cloud REST API documentation, there is a list of APIs available. However, it didn't give an example of a JSON template for certain scenarios. For this article, we list the JSON templates to create a new object based on each attribute type. Using the same JSON template, you can use it to update Asset objects using the REST API, too.
Using the Assets REST API
Follow the step-by-step to create a new object using the REST API :
Generate an API token for your account to execute the REST API using Basic Authentication:
Click Create API Token.
Set a Label and click Create.
Save the Token somewhere safe to use it for later.
Get the workspace ID for your site:
Run the API below:
https://<JSM Premium Site Name>.atlassian.net/rest/servicedeskapi/insight/workspace
From the response, save the workspace ID.
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
Structure the JSON template using the basic template as follows:
{ "objectTypeId": "250", "attributes": [ { "objectTypeAttributeId": "2797", "objectAttributeValues": [ { "value": "Test" } ] }, { "objectTypeAttributeId": "2807", "objectAttributeValues": [ { "value": "Testing" } ] } ] }
ObjectTypeID: You can get it from the Object Type configuration page.
ObjectTypeAttributeID: You can get it from the Object Type attribute configuration page.
Below is the detailed template for each attribute:
Attribute Type | Notes | Example |
Text | The value just needs to be the expected text. |
|
Boolean | The value can be either true or false. |
|
Integer | The value must be an exact number. |
|
Float | The value must be a floating number. |
|
Date | The value format is YYYY-MM-DD |
|
Date and Time | The value format is YYYY-MM-DDTHH:mm:ss.sssZ
|
|
URL | The value must start with HTTP:// or HTTPS:// |
|
The value must be a valid email format |
| |
Text Area | The value just needs to be the expected text. |
|
Select | The value must be the selection value name. This is an example of a single value. |
|
Select | The value must be the selection value name. This is an example of multi-value. |
|
IP Address | The value must represent IP Addresses (IPv4). This is an example of a single value. |
|
Reference Object | The value must be the reference object key. This is an example of a single value. |
|
Reference Object | The value must be the reference object key. This is an example of multi-value. |
|
Group | The value must be the group name. This example is for a single value. |
|
Group | The value must be the group name. This example is for a multi-value. |
|
User | The value must be the user's Atlassian Account ID. This example is for a single value. |
|
User | The value must be the user's Atlassian Account ID. This example is for a multi-value. |
|
Project | The value must be the project ID. You can get this via the REST API call |
|
Tips: For an 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.
Click View Source for the raw data.
For Postman, the request will look like the following example:
{
"objectTypeId": "23",
"attributes": [
{
"objectTypeAttributeId": "135",
"objectAttributeValues": [
{
"value": "NY-1"
}
]
},
Was this helpful?