Forums

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

Can't add watcher via Scriptrunner post-function (either 404s or adds "Initiating User")

Kyle Hollenbeck
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 25, 2022

I'm attempting to clone an issue using a Scriptrunner post-function and have had success copying over everything to the new issue except for "watchers".

My first attempt followed the recommendation on the support site as below:

def addWatcherResp = post("/rest/api/2/issue/clonedIssue.id/watchers")
.header("Accept", "application/json")
.header("Content-Type", "application/json")
.body('"${accountId}"')
.asObject(Map)

This consistently gives a "404 - Not Found error" response

I then tried the following:

def addWatcherResp = post("/rest/api/2/issue/clonedIssue.id/watchers?=${accountId}")
.asObject(Map)

which almost worked except it's only the "Initiating User" (so either Scriptrunner or the triggering user) that gets added as a watcher, not the accountId specified. I've tried several variations of this with no luck.

Interestingly, deleting an issue like below works fine for whatever user is specified:

def deleteWatcherResp = delete("/rest/api/2/issue/clonedIssue.id/watchers?accountId=${accountId}")
.asObject(Map)

Not really sure why this isn't working, but I'm about ready to give up on Scriptrunner for watcher management and create a branching link-triggered automation rule instead.

Any insight or help would be greatly appreciated, thanks!

1 answer

1 vote
Andrea Pannitti
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.
June 25, 2022

Hi @Kyle Hollenbeck,

with the REST Jira's API you can only add one user for time.
So, if you want add more users as watchers, you must itering them and call the REST api more times.
You can't even add groups, as is possible with native Jira's API

Kyle Hollenbeck
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 25, 2022

Thanks for the reply @Andrea Pannitti!

In this case I'm only trying to add one watcher, but am either getting a 404 response or the wrong user added as a watcher (initiated user instead of the one associated with the accountId specified).

My initial summary line didn't articulate this well though, so I've updated it to make the issue I'm experiencing more clear 👍

Andrea Pannitti
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.
June 25, 2022

Hi @Kyle Hollenbeck,

I noticed that the base url is missing in your REST call. Add it. I think this could solve your issue (to add one user only).

Suggest an answer

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

Atlassian Community Events