Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

What payload is required when creating an Assets object type reference attribute?

Rick Westbrock
Contributor
June 8, 2023

I have written a Python script which gets an object type and its attributes from a source tenant and schema then creates the object type and adds its attributes in a target tenant/schema. This works fine for simple attributes but I have run into a roadblock with reference attributes.

The way the script works is that it uses the response body from the GET object type attribute API as the payload to create the attribute in the target object type (after removing some properties such as workspaceId, globalId, id and objectType). For some properties it also must do a transform, for example the GET response has defaultType as a dict so I have to parse out the "id" from the dict and send that in the POST as defaultTypeId.

For reference attributes the GET response has dicts for referenceType and referenceObjectType so when I build the payload I am parsing out the "id" from each and POSTing them as referenceTypeId and referenceObjectTypeId. Using that method I am getting back an HTTP 400 bad request error with this payload though:

{'typeValue': 'Object Type invalid', 'additionalValue': 'ReferenceType invalid'}


Unfortunately the API documentation doesn't either of these properties so I can't even tell if creating a reference attribute with this API is supported. Any suggestions on the proper syntax for the payload? Below is what I am currently sending, I did try sending the referenceTypeId and referenceObjectTypeId as integers instead of strings (even though the GET response returns strings) but still get the same error.

{
'editable': True,
'hidden': False,
'includeChildObjectTypes': False,
'indexed': True,
'label': False,
'maximumCardinality': 1,
'minimumCardinality': 0,
'name': 'Service',
'options': '',
'position': 3,
'referenceObjectTypeId': '1',
'referenceTypeId': '1',
'removable': True,
'sortable': True,
'summable': False,
'system': False,
'type': 1,
'uniqueAttribute': False
}

2 answers

1 accepted

0 votes
Answer accepted
Mathias Scheck June 14, 2023

I´d like to know the answer as well...

 

Edit: found the solution (just look at the body which is sent via network-analysis in browser-development console).

 

{

    "additionalValue""1",

    "name""Your Name",

    "type""1",

    "typeValue""12345"

}
note: typeValue is the ObjectTypeID (the id of your referenced object-type) you are linking to
I hope this will help you.
Mathias Scheck June 14, 2023

I´ve also tested it for the following entries (which will all work):

The minimum required are the first 4.

Used via: POST /jsm/assets/workspace/{workspaceId}/v1/objecttypeattribute/{objectTypeId}

 
{

    "additionalValue""1",
    "name""Your Name",
    "type""1",
    "typeValue""12345",

    "editable"true,
    "hidden"false,
    "includeChildObjectTypes"true,
    "indexed"true,
    "iql""",
    "label"false,
    "maximumCardinality"-1,
    "minimumCardinality"0,
    "options""",
    "qlQuery""",
    "regexValidation""",
    "removable"true,
    "sortable"true,
    "suffix""",
    "summable"false,
    "system"false,
    "uniqueAttribute"false

}
Rick Westbrock
Contributor
July 11, 2023

Thanks very much @Mathias Scheck , somehow I wasn't added as a watcher to my own post so I didn't get a notification for your replies; fortunately I decided to come here to check directly.

I'll mark this as a correct answer once I have been able to try it on my side. Thanks very much for replying and I'll have to keep the browser console trick in mind for future development work, that's a great idea.

Like Mathias Scheck likes this
Rick Westbrock
Contributor
July 13, 2023

I used the payload from my script and changed 

referenceObjectTypeId to typeValue but got back HTTP 400 for "ReferenceType invalid" even though I was sending "4" which was returned by the Get objecttype attributes API https://developer.atlassian.com/cloud/assets/rest/api-group-objecttype/#api-objecttype-id-attributes-get
It turns out that this API does not return the required "additionalValue": "1" element so once I added that myself the POST was successful.
Thanks again @Mathias Scheck for your assistance!
Like Mathias Scheck likes this
Mathias Scheck July 13, 2023

You´re welcome.

0 votes
Rick Westbrock
Contributor
July 13, 2023

For anyone else following this I found that the "additionalValue" element is actually the reference type ID. I used Chrome's dev console to capture the payload when changing the reference type in the UI to find this:

{  
"id":"798",
"type":"1",
"expand":"operations",
"typeValue":"61",
"additionalValue":"3"
}

When changing the reference type to Reference "additionalValue" = 4.

In my script I had to parse out the referenceType.id from the Get objecttype attributes response to use in the additionalValue element of the payload when adding the attribute.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events