Add watcher progmmatically

Wendy Gao July 26, 2013

I wonder whether I can progmmatically add watchers to my Jira Issue through Java code instead of manually add it through web browser, for Jira 4.2 version? Is there an open source Jar for this purpose? Thanks.

4 answers

1 vote
RambanamP
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.
July 28, 2013

you can add watcher through REST api

/rest/api/2/issue/{issueIdOrKey}/watchers(POST)

check this doc

https://docs.atlassian.com/jira/REST/latest/#idp1884368

p.e using curl

curl -i -u admin:admin -H "Content-Type: application/json"-H "Accept: application/json"-X POST -d '"prasad"'http://localhost:8080/rest/api/2/issue/TEST-1/watchers

1 vote
RambanamP
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.
July 26, 2013

try with this code

WatcherManager watcherManager = ComponentManager.getInstance().getWatcherManager();
watcherManager.startWatching(user, issue.getGenericValue());	

(or)

	private UserAssociationStore userAssociationStore = ComponentManager
			.getComponentInstanceOfType(UserAssociationStore.class);
	public static final String ASSOCIATION_TYPE = "WatchIssue";
		userAssociationStore.createAssociation(ASSOCIATION_TYPE,user, issue.getGenericValue());

Wendy Gao July 28, 2013

Thanks. However I can not find a .jar file to download for this WatcherManager, I wonder whether this is open source, especially for Jira 4.2 version? Do you happen to know a place to download its related .jar file? Thanks a lot.

RambanamP
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.
July 28, 2013

hey! i have updated my answer, it should work on jira 4.2, if not let me know

1 vote
Bhushan Nagaraj
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.
July 26, 2013

Hey Wendy,

You need to use WatcherManager. Refer to the API here

https://docs.atlassian.com/jira/latest/com/atlassian/jira/issue/watchers/WatcherManager.html

Thank you
Bhushan

Wendy Gao July 28, 2013

Thanks. However I can not find a .jar file to download for this WatcherManager, I wonder whether this is open source, especially for Jira 4.2 version? Do you happen to know a place to download its related .jar file? Thanks a lot.

Bhushan Nagaraj
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.
July 28, 2013

Hi Wendy,

You can develop your own plugins to add functionality to Jira. Refer to the Jira plugin development guide.

https://developer.atlassian.com/display/JIRADEV/JIRA+Developer+Documentation

There are several tutorials available there. I have a simple tutorial avaiable here which you may also find helpful.

https://bitbucket.org/bhushan154/jira-issue-tab-panel-tutorial/wiki/Home

Cheers

Bhushan

Wendy Gao July 28, 2013

Maybe I did not explain clearly, I am not trying to make modification to my Jira server service, I am trying to automatically create issue and add watchers through another Java program which is not a part or plugin of the Jira server. I am trying to communicate with the Jira server through this other program, rather than through web browser. I guess to build a plugin is to change the Jira server itself and we do not want to do that. We just want to communicate with the server side through program. Sorry for the confusion. Do you have any suggestion towards what I am doing? thanks.

1 vote
Bhushan Nagaraj
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.
July 26, 2013

Hey Wendy,

You need to use WatcherManager. Refer to the API here

https://docs.atlassian.com/jira/latest/com/atlassian/jira/issue/watchers/WatcherManager.html

Thank you
Bhushan

Suggest an answer

Log in or Sign up to answer