Rest API - Add Issue Watcher to an Issue

Is it possible to add a watcher (or multiple watchers) via Rest API to an Issue? We've tried adding a watcher via API, but everytime we called POST on an Issue with a watcher in request content. Body looked like:

{
    "watchers": {
        "hasStar": true,
        "issueWatchers": [
            {
                 "user": {
                       "login": USER_LOGIN_HERE,
                       "$type": "jetbrains.charisma.persistence.user.User"
                  },
                 "$type": "jetbrains.charisma.persistent.issue.IssueWatcher"
            }
         ],
        "$type": "jetbrains.charisma.persistent.issue.IssueWatchers"
     }
}

Watcher was added, but it was always our user (user whose token was used to call the API). Is it possible to add different user as a watcher using the same token?

5 comments
Comment actions Permalink
Official comment

Hello Daniel,

I'm sorry for the delayed response.

Here's the example of a request to add a watcher:

You can add other users as watchers via command: `start <user_login>`. Here you can learn how to apply commands via REST: https://www.jetbrains.com/help/youtrack/incloud/resource-api-commands.html#create-CommandList-method

POST https://<base_url>/api/commands

{
"query": "star <user_login>",
"issues": [
{
"id": "<issue_id>"
}
]
}

Let us know if you need any assistance, we'll be happy to help.

Comment actions Permalink

Is there a way to set watchers in issue creation request ?
Or maybe to set watchers to draft and then publish it ?

0
Comment actions Permalink

Hi,

Yes, it is totally possible to set watchers in a draft. After that, you can execute a request that will publish the draft.

Here is an example of adding a watcher to a draft:


curl -X POST '/api/issues/2-5333/watchers/issueWatchers' -H 'Authorization: Bearer ' -H 'Content-Type: application/json;charset=UTF-8' -H 'Accept: application/json, text/plain, */*' -d '{"user":{"id":"1-206"},"isStarred":true}'

where 2-5333 is the id of your draft, 1-206 is the id of the user you want to set as a watcher.

Also, here is an example of publishing a draft:


curl -X POST '/api/issues?draftId=2-5333' -H 'Authorization: Bearer ' -H 'Content-Type: application/json;charset=UTF-8' -H 'Accept: application/json, text/plain, */*' -d '{"issueId":"2-5333"}'

where 2-5333 is the id of your draft.


Generally, you can just open the browser console and check the requests YouTrack executes itself. This is the very same REST API.

Hope it helps.

0
Comment actions Permalink

Thanks, Anastasia!

Is it only able to assign one user per request ? I have tried to pass a list of dicts, but received only a 500 error.

P.S. I would appreciate if you could mention this resource path in OpenAPI specification or Developer Portal

0
Comment actions Permalink
Hi,

User interface allows adding one user or group per request, so I believe there is no other way then to send a request for each watcher.
As for mentioning the endpoint in the OpenAPI documentation, I will share this request with the documentation team too. However, I'm afraid the final solution on whether an endpoint is to be published is up to the team. This is due to compatibility reasons - we are doing our best to ensure your custom integrations that use the offiical API are compatible with newer YouTrack versions.
0

Please sign in to leave a comment.