Could not find valid 'id' or 'name' in object when using the ADD operation for REST API

Still need help?

The Atlassian Community is here for you.

Ask the community

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

{"update":{"fixVersions":[{"add":[{"name":"versionone"}]}]}}

Error thrown

{"errorMessages":[],"errors":{"fixVersions":"Could not find valid 'id' or 'name' in version object."}}

OR

Using the following data to update Components

{"update":{"components":[{"add":[{"name":"componentone"}]}]}}

Error thrown

{"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

{"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:

  1. they all only support existing values, so using ADD to create additional values is not possible.
  2. 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:

    {"update":{"fixVersions":[{"add":{"name":"version2"}},{"remove":{"name":"version1"}}]}}
    tip/resting Created with Sketch.

    Because they only support "single" values, having square brackets [...] in front of ADD or REMOVE won't work

  3. 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:

    {"update":{"fixVersions":[{"set":[{"name":"version1"},{"name":"version2"}]}]}}

Resolution

Remove the extra square brackets for the ADD operation

{"update":{"fixVersions":[{"add":{"name":"versionone"}}]}}

Last modified on Oct 14, 2022

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.