【问题标题】:Failure in updating Atlassian Jira label using REST API使用 REST API 更新 Atlassian Jira 标签失败
【发布时间】:2017-12-25 12:04:42
【问题描述】:

我正在尝试使用 postman 和 curl 更新 Jira 标签,但这两种方法都失败并显示不同的错误消息。

curl -D- -u 用户名 -X PUT --data "{ "update": { "labels": [ {"add" : "new_label"} ] } }" -H "内容类型:应用程序/json" https://jira-internal.net/rest/api/2/issue/APP-12345

格式化的输入json

{  
   "update":{  
      "labels":[  
         {  
            "add":"new_label"
         }
      ]
   }
}

回复:

HTTP/1.1 400 Bad Request
Cache-Control: no-cache, no-store, no-transform
Content-Type: application/json;charset=UTF-8
Date: Thu, 20 Jul 2017 00:32:30 GMT
Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=7D2377622EC43724B9EF35E0CA7F6E20; Path=/; Secure; HttpOnly
Set-Cookie: atlassian.xsrf.token=BEF9-GHD2-UUG5-5KAQ|dc2355ac9338b0cc1396b1fd68a8268785ac6589|lin; Path=/; Secure
X-AREQUESTID: 32x6573810x14
X-ASEN: SEN-2063834
X-ASESSIONID: 1ak5dqh
X-AUSERNAME: userName
X-Content-Type-Options: nosniff
X-Seraph-LoginReason: OK
transfer-encoding: chunked
Connection: keep-alive

{"errorMessages":["Unexpected character ('u' (code 117)): was expecting double-quote to start field name\n at [Source: org.apache.catalina.connector.CoyoteInputStream@6e73489c; line: 1, column: 4]"]}%

使用邮递员时出现以下错误:

<html>
 <head>
 <title>Apache Tomcat/7.0.55 - Error report</title>
 <style>
 <!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}-->
 </style>
 </head>
 <body>
 <h1>HTTP Status 415 - Unsupported Media Type</h1>
 <HR size="1" noshade="noshade">
 <p>
 <b>type</b> Status report
 </p>
 <p>
 <b>message</b>
 <u>Unsupported Media Type</u>
 </p>
 <p>
 <b>description</b>
 <u>The server refused this request because the request entity is in a format not supported by the requested resource for the requested method.</u>
 </p>
 <HR size="1" noshade="noshade">
 <h3>Apache Tomcat/7.0.55</h3>
 </body>
</html>

【问题讨论】:

    标签: curl jira jira-rest-api


    【解决方案1】:

    使用 curl 的解决方案:

     curl -u userName -X PUT --data "{ \"update\": { \"labels\": [ {\"add\" : \"test_Label\"} ] } }" -H "Content-Type: application/json" https://url/rest/api/2/issue/APP-1234
    

    curl -u userName -X PUT --data '{ "update": { "labels": [ {"add" : "test_label"} ] } }' -H "Content-Type: application/json" https://url/rest/api/2/issue/APP-1234
    

    注意 JSON 数据周围的“'”。

    对于邮递员:

    1. 标题选项卡:内容类型:应用程序/json
    2. 确保将 json 数据作为原始数据添加到正文并选择 JSON 类型。

    【讨论】:

    • 这行得通。 Jira API 文档不够清晰。谢谢
    【解决方案2】:

    尝试更改您的呼叫添加""" 而不是"

    curl -D- -u userName -X PUT --data "{"""update""": {"""labels""": [ {"""add""": """new_label"""}]}}" -H "Content-Type: application/json" https://jira-internal.net/rest/api/2/issue/APP-12345
    

    对于邮递员来说,看看这个答案:Http 415 Unsupported Media type error with JSON

    【讨论】:

    • 感谢@Roberto,但这不起作用。我找出正确的转义字符。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-18
    • 1970-01-01
    • 2018-06-24
    • 2015-08-28
    • 1970-01-01
    • 1970-01-01
    • 2012-05-25
    相关资源
    最近更新 更多