Setting References for Assets via REST API in Jira

Hello Jira Community,

I’m currently working on a project that requires creating Assets and their associated References by utilizing the Assets API.

To date, I’ve been successful in generating Assets and defining their attributes by leveraging the POST Object create method. However, when it comes to setting References, I’ve encountered a stumbling block.

From what I’ve gathered, References don’t seem to exist as attributes of an Asset, but are only accessible via the GET Object referenceinfo method. I noticed that there’s no apparent POST or PUT method for them mentioned in the REST API documentation.

I’m curious to know whether it’s possible to set references through the REST API, or is this a task that can only be accomplished via the GUI?

Any insight or guidance on this matter would be greatly appreciated.

Thank you in advance for your assistance and expertise.

2 Likes

Hi @Abelardo

Apologies for the late response. Welcome to our community.

Good question! Let me check with my team. Thanks.

1 Like

Is there an answer to this question, I am going through the same problem and your answer would be very useful to me.

1 Like

You can mention the referenceinfo while creating the object. Here is an example:

curl --location --request POST 'https://api.atlassian.com/jsm/insight/workspace/{{workspace-id}}/v1/object/create' \
--header 'Authorization: Basic token' \
--header 'Content-Type: application/json' \
--data-raw '{
    "objectTypeId": "38", # Software object type
    "attributes": [
        {
            "objectTypeAttributeId": "97", # Software's name object type
            "objectAttributeValues": [
                {
                    "value": "Libre" # Software's name object value
                }
            ]
        },
        {
            "objectTypeAttributeId": "251", # Operating system object type
            "objectAttributeValues": [
                {
                    "value": "OPS-10" # Operating system object value (in this case, this could Linux)
                }
            ]
        }
    ]
}'

Here, I am assuming that the ‘Software’ is the child object of ‘Operating system’ and here I am creating a Software object while also adding OS as reference. I was able to test this out successfully.

Hi, @aagrawal2

I tried with the key pair "value": "OPS-10" in the request body, and a 400 error is returned.

OPS-10 is not a valid object ID or key

I have referenced the Response listed in Get object {id} and there is no key named “value”.

Which key must be specified in “objectAttributeValues”?

      "objectTypeAttributeId": "144",
      "objectAttributeValues": [
        {
          "referencedObject": {
            "workspaceId": "f1668d0c-828c-470c-b7d1-8c4f48cd345a",
            "globalId": "f1668d0c-828c-470c-b7d1-8c4f48cd345a:87",
            "id": "87",
            "label": "Sydney",
            "objectKey": "ITSM-87",
            "avatar": {
              "workspaceId": "f1668d0c-828c-470c-b7d1-8c4f48cd345a",
              "url16": "https://api.atlassian.com/jsm/assets/workspace/f1668d0c-828c-470c-b7d1-8c4f48cd345a/v1/objecttype/24/icon.png?size=16",
              "url48": "https://api.atlassian.com/jsm/assets/workspace/f1668d0c-828c-470c-b7d1-8c4f48cd345a/v1/objecttype/24/icon.png?size=48",
              "url72": "https://api.atlassian.com/jsm/assets/workspace/f1668d0c-828c-470c-b7d1-8c4f48cd345a/v1/objecttype/24/icon.png?size=72",
              "url144": "https://api.atlassian.com/jsm/assets/workspace/f1668d0c-828c-470c-b7d1-8c4f48cd345a/v1/objecttype/24/icon.png?size=144",
              "url288": "https://api.atlassian.com/jsm/assets/workspace/f1668d0c-828c-470c-b7d1-8c4f48cd345a/v1/objecttype/24/icon.png?size=288",
              "objectId": "87",
              "mediaClientConfig": {
                "clientId": "1a2s3d4f-dc47-44b0-9t0r-1h2h3yd68e9q",
                "mediaBaseUrl": "https://api.media.atlassian.com",
                "mediaJwtToken": "eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiIxYTJzM2Q0Zi1kYzQ3LTQ0YjAtOXQwci0xaDJoM3lkNjhlOXEiLCJhY2Nlc3MiOnsidXJuOmZpbGVzdG9yZTpmaWxlOjg0MTIzZXJ0LTEyM2MtNGIxMi0xMmM1LTBiODZkYzgxMjNmZiI6WyJyZWFkIl19LCJleHAiOjE2MjYxNTY1NjcsIm5iZiI6MTYyNjE1NTkwN30.YjicbagPLbzapp3eEZbCQ7Z9V8Uc0WeBledyTw-Qu0s",
                "fileId": "84123ert-123c-4b12-12c5-0b86dc8123ff"
              }
            },
            "objectType": {
              "workspaceId": "f1668d0c-828c-470c-b7d1-8c4f48cd345a",
              "globalId": "f1668d0c-828c-470c-b7d1-8c4f48cd345a:24",
              "id": "24",
              "name": "City",
              "icon": {
                "id": "28",
                "name": "Cottage",
                "url16": "https://api.atlassian.com/jsm/assets/workspace/f1668d0c-828c-470c-b7d1-8c4f48cd345a/v1/objecttype/24/icon.png?size=16",
                "url48": "https://api.atlassian.com/jsm/assets/workspace/f1668d0c-828c-470c-b7d1-8c4f48cd345a/v1/objecttype/24/icon.png?size=48"
              },
              "position": 3,
              "created": "2021-02-16T19:58:45.698Z",
              "updated": "2021-04-16T15:17:03.393Z",
              "objectCount": 0,
              "objectSchemaId": "6",
              "inherited": false,
              "abstractObjectType": false,
              "parentObjectTypeInherited": false
            },
            "created": "2021-02-16T20:04:26.445Z",
            "updated": "2021-02-16T20:04:26.445Z",
            "hasAvatar": false,
            "timestamp": 1613505866445,
            "_links": {
              "self": "https://api.atlassian.com/jsm/assets/workspace/f1668d0c-828c-470c-b7d1-8c4f48cd345a/v1/object/87"
            },
            "name": "Sydney"
          },
          "displayValue": "Sydney",
          "searchValue": "ITSM-87",
          "referencedType": true
        }
      ],

hmmm…interesting. That should work. Another value that works is referenced object ID. In your given JSON, that would be "id": "87", in referencedObject key. Give it a try and let me know.

The response returned a status code of 200. Unfortunately, the referenceinfo does not reflect the value I specified and is a null value.

I tried the following request body in JSON format.

{
  "objectTypeId": "38",
  "attributes": [
    {
      "objectTypeAttributeId": "97",
      "objectAttributeValues": [
        {
          "value": "Libre"
        }
      ]
    },
    {
      "objectTypeAttributeId": "251",
      "objectAttributeValues": [
        {
          "referencedObject": {
          	"id": "87"
          	}
        }
      ]
    }
  ]
}

@MasayukiAbe Where you have "referencedObject": { "id": "87" }

It should simply be { "value": 87 }

3 Likes

@DarrylBanks I wasn’t able to get the “value” to work within the “referencedObject”; however, I was able to get this:

  "objectAttributeValues": [
    {
        "value": "LV-88056"            OR         "value": 88056
    }

to work for references and statuses. If using the object id of the reference, then pass in as int. If using the key, then put in quotes. I guess the logic is strong enough to recognize the attribute is a reference and therefore looks for the key or id in the value.

1 Like