Since this has cost me a lot of nerves over the last few days and unfortunately the documentation is silent about the required values, here is a short HowTo
To update an issue and fields of an issue, use the following REST API endpoint:
Unfortunately, the documentation says nothing about the format in which elements in an Asset Custom Field should be passed.
This is what the JSON body must look like to fill an asset field. Alternatively, you can of course also use the other keywords from the documentation (“add”, “remove”, etc.):
"update": {
"customfield_XXXXX": [
{
"set": [
{
"workspaceId": "workspaceId ot the Object",
"id": "GlobalId ot the Object (workspaceId:objectId)",
"objectId": "Id of the Object"
}
]
}
]
}
The Global ID consists of the WorkspaceId and the objectId.
Here is an example of what such a body (with values) could look like:
"update": {
"customfield_10217": [
{
"set": [
{
"workspaceId": "ecaa45c7-4578-420f-a2e0-cf7b0da4b5ad",
"id": "ecaa45c7-4578-420f-a2e0-cf7b0da4b5ad:1672",
"objectId": "1672"
}
]
}
]
}
I'm happy if the information helps a few more people 🙂
@Salzi Are you sure "add"/"remove" operations will work ? I see only "set" in the operations list for the asset custom fields.
This is for a scenario, when we want to just add a new Asset to an Asset custom field which supports multiple objects.
@Salzi Thanks for the explenation.
This saved me a lot of time to figure it out myself!
@Salzi Thanks for sharing your findings, but I can't get it to run via postman.
Using this endpoint:
https://mycompany.atlassian.net/rest/api/3/issue/{{issue}}
With:
"update": {
"customfield_10190": [
{
"set": [
{
"workspaceId": "my-workspace-id",
"id": "my-workspace-id:30409",
"objectId": "30409"
}
]
}
]
}
I get:
{
"errorMessages": [
"Invalid request payload. Refer to the REST API documentation and try again."
]
}
Could you please check, if you have a different body in the postman request?
Thanks and Cheers,
Alex
I had to wrap the whole thing in an extra set of curly braces :)
does the on-premise JIRA/Assets solution has a workplace id to?
How can I set such a custom field in the on-premise JIRA?
TiA
Greetings
I was able to find the on-premise examples here. It's much simpler.
You just do a regular PUT Jira REST API issue edit of the custom field.
What you pass as the value is different from most custom fields, but simple enough.
Available actions are: add, set, remove.
For example:
{"update":{"customfield_98765":[{"add":[{"key":"TEST-123456"}]}]}}
The key value is the asset key.
I wonder if anyone else got this one to work? "Add" didn't work for me at all, so I tried "set", which appeared to work (204 response) and every possible combination of objectId, objectKey, and key, with and without quotation marks, and while I kept getting a 204 response, it was not correctly identifying the asset and just updating the field to ... blank.
This (OP's suggestion) worked for me, BUT I had to wrap the entire thing in another set of curly braces. Perhaps obvious to some but it took some poking for me to figure it out :)