I have followed the example given in this thread:
https://community.atlassian.com/t5/Jira-questions/ScriptRunner-for-Jira-Cloud-Add-watcher-in-ScriptRunner-Post/qaq-p/1177008
which points to this example:
https://bitbucket.org/snippets/Adaptavist/yAdX6X?_ga=2.267944206.120189328.1585505760-1987078914.1573938112
I created a ScriptRunner script and added it as a post-function on the Create transition, and I get error 404 below.
When I run the watchers REST API from a browser (after the ticket was created), it succeeds.
I suspect that the problem is that the issue is not yet in the database and hence the 404.
Can someone suggest another way to add watchers in the Create transition?
Thanks
2021-08-08 10:33:37.625 INFO - POST /rest/api/2/issue/IMR-262/watchers asString Request Duration: 398ms
2021-08-08 10:33:37.626 WARN - POST request to /rest/api/2/issue/IMR-262/watchers returned an error code: status: 404 - Not Found
body: {"errorMessages":[],"errors":{}} Code:
def issueKey = issue.key
["john.doe@example.com", "j.l.picard@enterprise.gov"].each { accountId ->
def result = post('/rest/api/2/issue/' + issueKey + '/watchers')
.header('Content-Type', 'application/json')
.body("\"${accountId}\"")
.asString()
}