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
}
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"
}
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
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I used the payload from my script and changed
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.