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?
Please sign in to leave a 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.
Is there a way to set watchers in issue creation request ?
Or maybe to set watchers to draft and then publish it ?
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:
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:
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.
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
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.
Hi,
Are we able to add multiple watchers per request? ..I have tried adding 2 watchers but got a status error:500
P.S. I would appreciate if you could mention this resource path in documentation.
Thank you.
Graj you should sen a separate request for each user. As for resource paths, not all of them (especially smaller ones) are currently available in the documentation, though we regularly publish them.