Developer Portal for YouTrack and Hub Help

400 Bad Request When Adding a Custom Field Value to a Set

This article examines an error that might occur when you update a set of values (bundle) using YouTrack REST API. You can face this error while figuring out the correct URL to access a specific bundle for a project custom field.

Error Message

{ "error": "Bad Request", "error_description": "Entity id 70-519 refers to entity of type BundleProjectCustomField, while entity of type ProjectVersionsBundle is expected" }

Request Details

Here are the details about a sample request that might result in this error.

Attribute

Value

Request method

POST

Endpoint

/api/admin/customFieldSettings/bundles/version/versionBundleID/values

Request body

{ "name": "October sprint", "$type": "VersionBundleElement" }

HTTP response code

400

Use Case

You want to add a value to a bundle in a project custom field. You've decided to do this by accessing the bundle from the global list of bundles.

You have tried to figure out the ID of the target bundle and define the correct endpoint for the POST request. However, instead of the ID of the bundle, you've used the ID of the project custom field prototype in the request URL.

To define the correct request URL, you need to determine the ID of the target bundle. If you send a GET request to /admin/projects/projectID/customFields?fields=id,field(name,fieldType),project(shortName),bundle(id,name), here's the response body:

..., { "bundle": { "name": "New Project: Versions", "id": "59-2", "$type": "VersionBundle" }, "field": { "name": "Affected versions", "fieldType": { "$type": "FieldType" }, "$type": "CustomField" }, "project": { "shortName": "NP", "$type": "Project" }, "id": "82-13", "$type": "VersionProjectCustomField" }, ...

Now, if you take ID 82-13 (the ID of the project custom field prototype) and use it instead of the bundle ID (59-2), you will get the error described in this article.

Troubleshooting

Here are some possible causes and suggestions on how to overcome this error and add a value to the target set.

Cause

The ID of the target bundle used in the request URL is incorrect.

Solution 1

Replace the ID of the project custom field with 59-2, which is the ID of the target bundle, in the request URL.

To locate the ID of the target bundle, look at the structure of the response body that you received from the GET request. You get a collection of project custom fields with their attributes in the response. The bundle attribute is one of the attributes of the ProjectCustomField entity. You can find the ID of the bundle inside the bundle object.

Each custom field in a project has its ID. In our example, this ID is 82-13. You can use this ID in those requests that update this project custom field.

In this case, you want to update the bundle that's attached to this project custom field, so you need to use the ID of the bundle. You can find the ID of the bundle in the response to the GET request on the same level as the type of the bundle: "$type": "VersionBundle". When you're unsure which ID to use, consider the entity type as your safety net.

The error message indicates that in this particular request, YouTrack expects an entity of the ProjectVersionsBundle type instead of BundleProjectCustomField.

The final request URL in this case would be /api/admin/customFieldSettings/bundles/version/59-2/values where 59-2 is the ID of the target bundle.

For more details about custom field hierarchy in the YouTrack REST API, see Custom Fields in REST API.

Solution 2

Change the endpoint and work with the bundle of the particular custom field in the project instead of the global list of bundles.

The updated endpoint would be /api/admin/projects/projectID/customFields/projectCustomFieldID/bundle/values. This resource lets you access the bundle of a particular custom field in a specific project.

To compose the URL for a valid request, you need the ID of the project and the ID of the project custom field. To get the ID of the project, make a GET request to the global list of projects. As for the ID of the project custom field, it's 82-13 from the initial request.

The final request URL in this case would be /api/admin/projects/81-1/customFields/82-13/bundle/values where 81-1 is the ID of the target project, and 81-1 is the ID of the target bundle.

Last modified: 30 April 2024