问题
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.
回答1:
The issue is propably in this line:
data: "{\"update\":{\"comment...
Get rid of \ and change this to a javascript-object: data: {"update": "bla bla" ...
I think you just copied over the text from curl.
来源:https://stackoverflow.com/questions/44351198/unable-to-put-comment-to-jira-with-javascript-using-rest-api