无法使用REST API使用Javascript将评论添加到Jira [英] Unable to PUT comment to Jira with Javascript using REST API

查看:114
本文介绍了无法使用REST API使用Javascript将评论添加到Jira的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过JavaScript用新注释更新jira.我可以整天使用cURL做到这一点,但事实证明使用javascript更具挑战性.我能够调用Jira API以获取密钥的GET请求,因此我知道我的标头/身份验证正在工作.问题是我的数据.我看不到我在用注释格式化JSON字符串时做错了什么.这是我到目前为止的内容:

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);
}
});

我不断收到400错误请求.再加上ajaxOptions只会返回错误",因此Jira没有任何迹象表明它为什么会抱怨.

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.

感谢您的指导.

推荐答案

此问题可能在以下一行中出现:

The issue is propably in this line:

data: "{\"update\":{\"comment...

摆脱\并将其更改为javascript对象: 数据:{"update":"bla bla" ...

Get rid of \ and change this to a javascript-object: data: {"update": "bla bla" ...

我认为您只是复制了curl中的文本.

I think you just copied over the text from curl.

这篇关于无法使用REST API使用Javascript将评论添加到Jira的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆