How to Add Watchers to an Issue?

Denis Shvetsov August 17, 2022

Hello. So, I'm trying to add a particular person as a watcher to a number of issues via API, but it doesn't work.

According to this page https://docs.atlassian.com/software/jira/docs/api/REST/1000.824.0/#api/2/issue-addWatcher, (the `example` there is exceptionally helpful, btw), I'm supposed to send POST request to `/rest/api/2/issue/{issueIdOrKey}/watchers` with a `username` for a parameter. However, when I do that, my own user gets added to watchers, not the desired user that I send in params. I still get 204, which is a success code here.

URL I'm using:

('https://company.atlassian.net/rest/api/2/issue/issue_key/watchers', auth=auth, headers=headers, params=params)
headers = {
"User-Agent": "dummyValue",
"X-Atlassian-Token": "no-check",
"Accept": "application/json",
"Content-Type": "application/json",
}

params (with the email of the desired user)

{"username": "JoeSmith@company.com"}

What am I doing wrong?

P.S.: I'm kinda confused by the 'username' entity. When I get a user object via API, it has 'emailAddress', 'accountId' and 'displayName' parameters, - but not a `username`. What's up with that?

1 answer

1 vote
Prince Nyeche
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.
August 17, 2022

You're using an old doc. Cloud instances deprecated username. Therefore, you should use accountId if you want to add watchers to an issue. See this official doc for an example.

Denis Shvetsov August 17, 2022

Thank you!

Denis Shvetsov August 18, 2022

@Prince NyecheHey, by any chance, do you know how to deal with the authorization issues? I reworked the code, and now I'm getting 403 (not enough permissions), even though I'm admin on the project in question, and also explicitly added myself to the permission schema, 'manage watchers' section.

Prince Nyeche
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.
August 18, 2022

Are you able to edit the issue field? Check if you have permission for that.

Apoorva N September 14, 2023

@Prince Nyeche i am trying to use the updated doc and i am not able to get accountId param. Many people mention using Find users api and when i do that i only get jira key and not account id. also i tried groupuserpicker api - even this only gives jira key and not accountId. any idea why this would be happening?

Prince Nyeche
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.
September 14, 2023

You can use the searchUser API to return the account of any user within your environment. You have to parse the output to get the accountId key value. An example is shown on the docs

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events