Change Assignee with fetchYouTrack Host API
Hello everyone,
I am working on converting a curl command that sends a POST request to the YouTrack API into a JavaScript function that uses the YouTrack Host API's fetchYouTrack method. Here is the original curl request:
curl -X POST \
'https://example.youtrack.cloud/api/issues/SP-8?fields=customFields(id,name,value(avatarUrl,buildLink,color(id),fullName,id,isResolved,localizedName,login,minutes,name,presentation,text))' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer perm:am9obi5kb2U=.UG9zdG1hbiBKb2huIERvZQ==.jJe0eYhhkV271j1lCpfknNYOEakNk7' \
-H 'Content-Type: application/json' \
-d '{
"customFields": [
{"name": "Assignee", "$type": "SingleUserIssueCustomField", "value": {"login": "jane.doe"}},
{"name": "Priority", "$type": "SingleEnumIssueCustomField", "value": {"name": "Major"}},
{"name": "Fix versions", "$type": "MultiVersionIssueCustomField", "value": [{"name": "2019.1"}]},
{"name": "Requester email", "$type": "SimpleIssueCustomField", "value": "test@example.com"}
]
}'
How can I implement this command using the fetchYouTrack method?
I am complete new in creating a App in YouTrack
Thank you in Advance
Please sign in to leave a comment.
Hi Sentuerkemircan,
The fetchYouTrack equivalent will look like this:
The documentation describes the Host API and apps overall in more detail, so you can get started by following App Quick Start Guide and Host API.
Hi Julia Bernikova,
i did create a App and this is the code:
But i get the error:
when i try to change the Assignee from a Issue
Hi Sentuerkemircan,
It seems that the
JSON.stringify
call is unnecessary - you should be able to passrequestBody
as is.If the issue persists after removing it, please share the exact body passed to the request.
Hi Julia Bernikova,
that was the error. Removing JSON.stringify solved the problem, but why can't I use JSON.stringify?
Sentuerkemircan,
According to MDN and the YouTrack documentation, request parameters should be a JavaScript object (particularly RequestInit) rather than JSON.