Exact syntax to add a watcher to an existing Jira ticket with the REST API? Edited

Part of my C# program creates a Jira ticket (working) and, depending on the user who is creating the ticket, adds a watcher (not working).

URL that I'm using:  http://jira/rest/api/2/issue/TS-1000/watchers

I've done a lot of reading and the json syntax to add a watcher should be something like "{"username":"jdoe"}" but that synxtax, or any variation thereof (user instead of username, double quotes, single quotes, escaped quotes, etc) doesn't result in success.

The result of this code is

400 Bad Request

and

The request sent by the client was syntactically incorrect.

Can someone please give me a working JSON example to add a watcher that doesn't involve curl?  I'm not using curl and I don't know how to translate a curl command to json.

Thank you!

1 answer

After taking a closer look at https://community.atlassian.com/t5/JIRA-questions/add-watcher-json-syntax-used-for-jira-rest-api-java-jersey/qaq-p/168958 I saw that in OP's original code the JSON was being saved to a variable and then passed to the web request (like I was trying to do). 

But then in the answer OP stated that it wasn't working because the watcher username wasn't being passed with quotes surrounding the username variable.  But that's only half of the solution; I also noticed that the JSON variable wasn't being passed any longer - just the watcher username, surrounded by quotes, was being passed.

So the answer is to forget about the JSON and just pass the username with quotes.

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,905 views 12 18
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot