SimpleIssueCustomField vs SimpleProjectCustomField

I am trying to follow guide in docs: https://www.jetbrains.com/help/youtrack/standalone/api-howto-create-issue-with-fields.html

I am stuck at step 2: "Obtain the name and $type of the custom field that you need to set. You can send a GET request to the /api/issues endpoint with query parameters".

I don't understand why you are supposed to read an issue when you want to create a new one. For example, my project have no issues, and I want to create one via API. /api/issues will return an empty set. Now what?

I tried to call /api/admin/projects/TEST/customFields instead. This works, but returned $type is SimpleProjectCustomField. Attempt to create an issue: 

{
"project":{
"id":"0-0"
},
"summary":"Test",
"description":"Test",
"customFields":[
{
"name":"Test",
"value":1,
"$type":"SimpleProjectCustomField"
}
]
}

will fail with:

HTTP Error 500: (HTTP_STATUS_SERVER_ERROR) class jetbrains.charisma.customfields.simple.common.SimpleProjectCustomFieldMegaProxy cannot be cast to class jetbrains.charisma.persistence.customfields.IssueCustomField (jetbrains.charisma.customfields.simple.common.SimpleProjectCustomFieldMegaProxy and jetbrains.charisma.persistence.customfields.IssueCustomField are in unnamed module of loader org.eclipse.jetty.webapp.WebAppClassLoader @20e3dc94)

However, if I manually replace SimpleProjectCustomField with SimpleIssueCustomField:

{
"project":{
"id":"0-0"
},
"summary":"Test",
"description":"Test",
"customFields":[
{
"name":"Test",
"value":1,
"$type":"SimpleIssueCustomField"
}
]
}

Then this will be executed without a problem.

What am I missing? How do I obtain the "proper" $type?

1 comment
Comment actions Permalink
Official comment

Hello! 

This step 2 is suggested only to obtain the payload that you'll then be able to imitate in your POST request. I agree that if you don't have any issues in your YouTrack yet, this step would be useless, but usually, this helps you obtain all the required types for the POST request body.

When you need to obtain the right $type for your request, you need to pay attention to the custom field type. You can find the mappings here: https://www.jetbrains.com/help/youtrack/standalone/api-concept-custom-fields.html#type-issue-custom-fields

Feel free to check the whole page: https://www.jetbrains.com/help/youtrack/standalone/api-concept-custom-fields.html, it should help figure out how the custom fields are used in our REST API. 

If you have any questions, please feel free to ask, I'll be happy to help.

Please sign in to leave a comment.