Could not find valid 'id' or 'name' in object when using the ADD operation for REST API
Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.
Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
Problem
When using REST API to update an issue, specifically the ADD operation, Could not find valid 'id' or 'name' error is thrown.
Example
Using the following data to update Fix Version
1
{"update":{"fixVersions":[{"add":[{"name":"versionone"}]}]}}
Error thrown
1
{"errorMessages":[],"errors":{"fixVersions":"Could not find valid 'id' or 'name' in version object."}}
OR
Using the following data to update Components
1
{"update":{"components":[{"add":[{"name":"componentone"}]}]}}
Error thrown
1
{"errorMessages":[],"errors":{"components":"Could not find valid 'id' or 'name' in component object."}}
Diagnosis
Using the exact same data, but replacing ADD with SET works with no errors
1
{"update":{"components":[{"set":[{"name":"versionone"}]}]}}
Cause
There is an extra square bracket in the data file
First, a little explanation between SET, ADD and REMOVE:
they all only support existing values, so using ADD to create additional values is not possible.
ADD and REMOVE are opposites of each other, and they only support single values
e.g. if you already have 2 versions named version1 and version2, and an issue currently belongs to version1, the following json will add version2 to the issue and remove version1 from it i.e. moving the issue from version1 to version2:
1
{"update":{"fixVersions":[{"add":{"name":"version2"}},{"remove":{"name":"version1"}}]}}
Because they only support "single" values, having square brackets [...] in front of ADD or REMOVE won't work
SET supports both single and multiple values, so there must be square brackers [...] in front of SET
e.g. adding an issue to 2 existing versions:
1
{"update":{"fixVersions":[{"set":[{"name":"version1"},{"name":"version2"}]}]}}
Solution
Resolution
Remove the extra square brackets for the ADD operation
1
{"update":{"fixVersions":[{"add":{"name":"versionone"}}]}}
Was this helpful?