How to add an existing field to a project

This is a sort of follow-up question from https://youtrack-support.jetbrains.com/hc/en-us/community/posts/360000037744-Crea-a-new-Custom-field-with-REST-API

What about the new API?

I can't find an endpoint to add an existing custom field to a project.

It seems that https://www.jetbrains.com/help/youtrack/incloud/operations-api-admin-projects.html#update-Project-method is the endpoint to be used, but without a specific example, it's kind of shooting blindly to guess what's the right way to do it and with a high risk of messing our projects while testing.

0
1 comment
Official comment

Hi Andrea,

I'm sorry for the delayed response here.

To attach an existing field to a project, you need to:

1) Get the ID of your project from the list of projects: https://www.jetbrains.com/help/youtrack/incloud/resource-api-admin-projects.html#get_all-Project-method

GET https://<base-url>api/admin/projects?fields=id,name

2) Get the ID of your custom field from the list of custom fields: https://www.jetbrains.com/help/youtrack/incloud/resource-api-admin-customFieldSettings-customFields.html#get_all-CustomField-method

GET https://<base-url>/api/admin/projects/<project-id>/customFields?fields=field(name,id)

3) Attach the field to the project: https://www.jetbrains.com/help/youtrack/incloud/resource-api-admin-projects-projectID-customFields.html#create-ProjectCustomField-method

POST https://<base-url>/api/admin/projects/<project-id>/customFields?fields=field(name,id)

{
"field": {
"name": "My State",
"id": "46-12",
"$type": "CustomField"
},
"$type": "StateProjectCustomField"
}

Please sign in to leave a comment.