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.
@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 @ISSQ Account ,
Kindly ensure that you have necessary permissions to add watchers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
Thanks & Regards,
Luman.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @ISSQ Account ,
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/
import
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Niranjan,
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.
Thanks & Regards,
Luman.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.