Hello Atlassian Community,
I'm facing an issue with the JIRA API where I'm unable to programmatically attach assets to the "Asset Objects" custom field in JIRA.
Here's a brief context: I have a script that successfully creates assets in JIRA using the Assets API. However, the challenge arises when trying to link these assets to "Asset Objects" custom fields in selected issues.
Below is an excerpt from the script where the linking is attempted:
def link_asset_to_issue(asset_key, issue, project_key):
update_data = {
"fields": {
custom_field: [{"key": asset_key}]
}
}
issue.update(fields=update_data)
When this part of the script runs, it results in a HTTP 400 error with the message Field 'fields' cannot be set. It is not on the appropriate screen, or unknown.
(I have verified the fields are visible and will take the Asset Key as input on all the issues I am trying to update)
In the JIRA UI, interacting with this custom field requires clicking an "Add Object" button, followed by a validation step (checkmark or 'x'). This unique interaction model leads me to believe that the standard API update call might not suffice for this custom field.
I'm looking for guidance on how to correctly update the "Asset Objects" custom field via the API, considering its unique interaction requirements. Has anyone successfully updated this type of field programmatically? Any insights, API documentation references, or examples would be greatly appreciated.
Thank you for your assistance!
Hi,
It is rather confusing, because you find different approaches online.
I managed to get this to work in python code using the Atlassian library. Would that be of any help?
Regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Yes of course. In python using the Atlassian libraries it would look like this:
JIRA_CLOUD.update_issue_field(
key= "<issueKey>",
fields= {
"customfield_xxx": [
{
"workspaceId": "<workspaceId>",
"id": "<workspaceId>:<objectId>",
"objectId": "<objectId>"
}
]
}
)
This code assumes you have instantiated JIRA_CLOUD correctly with url, auth ... but this can all be found in the documentation. The workspaceId, depends on your Cloud instance.
Jeroen
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.