Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Rest API to add watchers to Issue

ISSQ Account October 9, 2020

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.

2 answers

0 votes
Derek Fields (RightStar)
Community Champion
October 9, 2020

@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.

0 votes
Niranjan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 9, 2020

Hi @ISSQ Account ,

Kindly ensure that you have necessary permissions to add watchers.

 

  • Browse projects project permission for the project that the issue is in.
  • If issue-level security is configured, issue-level security permission to view the issue.
  • To add users other than themselves to the watchlist, Manage watcher list project permission for the project that the issue is in.
ISSQ Account October 9, 2020

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.

Niranjan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 9, 2020

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)
ISSQ Account October 9, 2020

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.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
TAGS
AUG Leaders

Atlassian Community Events