首页 > 解决方案 > 使用 Jira API 的 curl 请求中出现意外的字符错误

问题描述

我正在尝试通过使用带有 Jira API 的 curl 请求来更新 Jira 问题中的字段,并使用Jira API 教程中的最后一个 curl 请求来创建我更改工单摘要字段的请求。

我使用了这个 curl 命令(用“DOMAIN”替换了实际域,用“MY_TOKEN”替换了我的 api 令牌):

curl -D- -u kim.tang@DOMAIN.com:MY_TOKEN -X PUT --data "data_file.json" -H "Content-Type: application/json" https://DOMAIN.atlassian.net/rest/api/2/issue/ZSTP-3511

我的“data_file.json”看起来像这样:

{
    "update" : {
        "summary" : [{"set" : "Big block Chevy"}]
    }
}

但我收到的错误信息是这样的:

PS C:\Users\de00180\Desktop> curl -D- -u kim.tang@DOMAIN.com:MY_TOKEN -X PUT --data "data_file.json" -H "Content-Type: application/json" https://DOMAIN.atlassian.net/rest/api/2/issue/ZSTP-3511
HTTP/1.1 400 Bad Request
Server: AtlassianProxy/1.15.8.1
cache-control: no-cache, no-store, no-transform
Content-Type: application/json;charset=UTF-8
Strict-Transport-Security: max-age=315360000; includeSubDomains; preload
Date: Thu, 22 Oct 2020 11:00:15 GMT
ATL-TraceId: 2b748183a0112486
x-arequestid: e929fb72-6adc-4cb7-84e4-f38f36c6e342
x-aaccountid: 5aec0e222d1bf924e1fc693d
X-XSS-Protection: 1; mode=block
Transfer-Encoding: chunked
timing-allow-origin: *
x-envoy-upstream-service-time: 21
X-Content-Type-Options: nosniff
Connection: close
set-cookie: atlassian.xsrf.token=BP6L-4GZ3-UVOB-X2BO_044d61b5148f4471cb04a8c58ac8f12ab76f2fd2_lin; Path=/; Secure
Expect-CT: report-uri="https://web-security-reports.services.atlassian.com/expect-ct-report/global-proxy", enforce, max-age=86400

{"errorMessages":["Unexpected character ('d' (code 100)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: org.apache.catalina.connector.CoyoteInputStream@5503a2e4; line: 1, column: 2]"]}

这里的另一个类似的问题是使用不同的错误代码,并且尝试更改引号字符对我不起作用。

但我也在使用 Windows,所以它可能连接到我的操作系统。

我还查看了curljira api错误代码,但它并没有帮助我解决这个问题,因为错误代码 100 仅代表 Jira 中的“继续”响应。

我该如何解决这个错误?

标签: curljira

解决方案


问题可能出在实际的 curl 命令中。我从这个答案中看到,如果您正在引用文件,则需要在文件名之前放置一个“@”。否则,它将“data_file.json”作为实际的请求正文。

尝试这个:

curl -D- -u kim.tang@DOMAIN.com:MY_TOKEN -X PUT --data "@data_file.json" -H "Content-Type: application/json" https://DOMAIN.atlassian.net/rest/api/2/issue/ZSTP-3511

推荐阅读