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
?
Please sign in to leave a 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.
Hello, this is not working.
I tried ...
```response from /api/admin/projects/project-id/customFields?fields=id,name
id: "some-id", name: "Категория", $type: "MultiOwnedIssueCustomField"
```
I await *$type: OwnedProjectCustomField* but ok... "MultiOwnedIssueCustomField"
Try to create issue with *canBeEmpty: false, emptyFieldText: null* field... body is:
```POST /api/issues?fields=id,idReadable
"summary": "Text...", "description": "Text....", "project": { "id": "project-id" },
"customFields": [ { "value": "IssetCategoryBundleValue...", "name": "Категория", "id": "some-id", "$type": "MultiOwnedIssueCustomField" } ]
```
and result is...
```
500 - {\"error\":\"server_error\",\"error_description\":\"class java.lang.String cannot be cast to class java.util.Collection (java.lang.String and java.util.Collection are in module java.base of loader 'bootstrap')\"}
```
2 Questions... Why i got MultiOwnedIssueCustomField when i must see OwnedProjectCustomField... and why i have error *class java.lang.String cannot be cast to class java.util.Collection*
When i use bundle...
custom fields in body:
```
```
error is:
```
500 - {\"error\":\"server_error\",\"error_description\":\"class jetbrains.charisma.customfields.complex.ownedField.OwnedBundleElementMegaProxy cannot be cast to class java.util.Collection (jetbrains.charisma.customfields.complex.ownedField.OwnedBundleElementMegaProxy is in unnamed module of loader org.eclipse.jetty.webapp.WebAppClassLoader @5dc79fea; java.util.Collection is in module java.base of loader 'bootstrap')\"}
```
First of all: it might be helpful to check out this article about the custom field structure in the YouTrack REST API. I believe it might help to make the custom field hierarchy more clear.
>> I await *$type: OwnedProjectCustomField* but ok... "MultiOwnedIssueCustomField"
Do I understand it right that you have received MultiOwnedIssueCustomField as the entity type in response to GET /api/admin/projects/project-id/customFields?fields=id,name ? If that's right, it's very strange. Could you please share the full request and the full response with us? Please send it with an email to youtrack-support@jetbrains.com or submit a ticket using the button on the top of this page.
>> Try to create issue with *canBeEmpty: false, emptyFieldText: null* field
Could you please also share the full payload for this request with us? The "value": "IssetCategoryBundleValue..." part in your request looks kind or truncated, so the full request might help us understand what's going on here.
>> When i use bundle...
Just to be on the same page - what do you mean by bundle here? Could you please share the full URL for this request?
JFYI: a couple of links to our documentation resources:
Here you can find a sample for creating an issue with certain custom field values.
Here you can find a step-by-step tutorial on creating an issue with certain custom field values.
Another thing I'd like to mention: we're aware of the comprehensibility issues of the API error messages, let us apologize for these. We'll do our best to improve the messages in future iterations.
thx, i sended all information to youtrack-support@jetbrains.com
tried all guides, wrote mapping projects > issues // issues > projects class, tried string, arrays, bundles, arrays of bundles.
always problem to casting this type: MultiOwnedIssueCustomField