I'm trying to update a jira with a new comment through JavaScript. I can do this all day long with cURL but using javascript is proving more challenging. I was able to call the Jira API for a GET request for a key so I know my headers/authentication is working. Problem is my data. I don't see what I'm doing wrong to format the JSON string with the comment. Here's what I have so far:
$.ajax({type: "PUT",url: "https://jira.domain.com/rest/api/2/issue/TEST-113",dataType: "json",headers: { "Authorization": "Basic " + userCredentials, "Content-Type": "application/json", 'X-Atlassian-Token': 'nocheck' },data: "{\"update\":{\"comment\":[{\"add\":{\"body\": \"Test comment\"}}]}}",success: function (json) { console.log(json) },error: function (xhr, ajaxOptions, thrownError) { console.log(xhr.status); console.log(thrownError); console.log(ajaxOptions); } });
I keep getting 400 Bad Request back. Plus ajaxOptions just returns "error" so I don't have any indication from Jira why it's complaining.
Thanks for any guidance.
You're creating a new comment, so you need to use the POST method. If you are updating an existing comment, then you use PUT (and supply the comment id at the end of the URL)
See https://docs.atlassian.com/jira/REST/server/#api/2/issue-addComment
Hi Tom,
Thanks for the help! While that's not what I was doing you still lead me to the right answer eventually.
So there's 2 ways to create a comment. The way I was trying it does use a PUT method but it uses a different JSON string hence the
{"update": { "comment" : [{"add" : {"body" : "Comment text goes here"}}]}}
I'm using that currently with cURL and it's working great.
What you showed me is a lot easier because while it uses POST, the URL adds a /comment after the jira key in the URL and the JSON I need to send is much simpler:
{"body": "Comment"}
Then it was still giving me a 400 error but after I used:
var sendComment = {"body": "Testing comment"} sendComment = JSON.stringify(sendComment);
I was able to send the data correctly and jira was happy to add a comment. Thanks for the help again!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.