Hi Team,
Can anybody help me to get the REST API to add watchers to an Issue. I tried providing the input JSON by passing the 'username' as {"username":"XXXXX"},'accountId' as {"accountId":"XXXXXXXX"} and 'displayname' as {"displayname":"XXXXX"} to the API 'https://XXXXX/rest/api/2/issue/IP-72/watchers' in Postman, but i was not able to add watchers to issue. Could anybody help me out on this.
Thanks & Regards,
Luman.
Hi @ISSQ Account ,
Kindly ensure that you have necessary permissions to add watchers.
@ISSQ Account It would be helpful if you could post your JSON here so that we can see exactly what is being passed. If the permissions are correct, then the most likely problem is the format of your JSON.
Hi Niranjan,
Thanks a lot for your quick response. It worked for me when I set the permissions. Could you please help me out how can i pass two or more watchers in json to the rest api.
Kindly check the script in this link. I have not tested it, but looks like it would work. I am not good with scripting, but you may need to get the usernames in a list and iterate over it.
https://justinit.wordpress.com/2010/12/17/jira-add-watchers-at-issue-creation/
com.atlassian.jira.ComponentManager def componentManager = ComponentManager.getInstance()def watcherManager = componentManager.getWatcherManager()def userManager = componentManager.getUserUtil() def watchUsers = {usernames -> usernames.each { def user = userManager.getUser(it) watcherManager.startWatching(user, issue.getGenericValue()) }} def users = ["comma", "separated", "usernames"] watchUsers(users)import
com.atlassian.jira.ComponentManager
def
componentManager = ComponentManager.getInstance()
watcherManager = componentManager.getWatcherManager()
userManager = componentManager.getUserUtil()
watchUsers = {usernames ->
usernames.
each
{
user = userManager.getUser(it)
watcherManager.startWatching(user, issue.getGenericValue())
}
users = [
"comma"
,
"separated"
"usernames"
]
watchUsers(users)
I tried passing the username in double quotes in the json, but i was not able to add watchers to issue. I tried passing accountId in double quotes. Then i was able to add watchers to issue. But now when i tried passing more than 1 accountId in double quotes by coma separated values, it is throwing 404 bad request. Could u please help me out on this.
It looks like you're new here. Sign in or register to get started.