Forums

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

Unable to Attach Assets to "Asset Objects" Custom Field via JIRA API

Felipe Luisi
Contributor
November 30, 2023

 

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!

2 answers

1 vote
Jeroen Poismans
Community Champion
December 1, 2023

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

0 votes
Deleted user March 20, 2024

Hi can I have this example?

Greets

Jeroen Poismans
Community Champion
March 25, 2024

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

 

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