Unable to PUT comment to Jira with Javascript using REST API

混江龙づ霸主 提交于 2021-02-11 13:05:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!