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

 

 

 

0
5 comments

Hi Sentuerkemircan,

The fetchYouTrack equivalent will look like this:

const queryParams = {method: 'POST', body: {customFields: [{name: "Assignee", $type: "SingleUserIssueCustomField", value: {login: "jane.doe"}}]}}; // Add the rest of the custom fields in a similar manner
const appResponse = await host.fetchYouTrack('issues/SP-8?fields=customFields(id,name,value(avatarUrl,buildLink,color(id),fullName,id,isResolved,localizedName,login,minutes,name,presentation,text))', queryParams);

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.

1

Hi Julia Bernikova,

i did create a App and this is the code:
 

       const requestBody = {
           customFields: [
               {
                   name: "Assignee",
                   $type: "SingleUserIssueCustomField",
                   value: newAssignee ? { id: newAssignee.id } : null
               }
           ]
       };


host.fetchYouTrack(
               `issues/${issue.id}`,
               {
                   method: "POST",
                   headers: { "Accept": "application/json", "Content-Type": "application/json" },
                   body: JSON.stringify(requestBody),
               }

But i get the error:

data: 
message: "Request failed."
servlet:"gap-rest-servlet"
status:
"500"
url:"/api/issues/3-40"

when i try to change the Assignee from a Issue

 

0

Hi Sentuerkemircan,

It seems that the JSON.stringify call is unnecessary - you should be able to pass requestBody as is.

If the issue persists after removing it, please share the exact body passed to the request.

1

Hi Julia Bernikova,

that was the error. Removing JSON.stringify solved the problem, but why can't I use JSON.stringify?

0

Sentuerkemircan,

According to MDN and the YouTrack documentation, request parameters should be a JavaScript object (particularly RequestInit) rather than JSON.

1

Please sign in to leave a comment.