2017-07-20 99 views
0

我正在嘗試使用郵遞員和curl更新Jira標籤,但這兩種方法都失敗並顯示不同的錯誤消息。使用REST API更新Atlassian Jira標籤失敗

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

格式化輸入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: [email protected]; 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> 

回答

1

解決方案與捲曲的工作:

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

OR

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類型。

Body tab

0

試圖改變您的通話將"""代替"

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

+0

感謝@Roberto但這不起作用。我找出正確的轉義字符。 – Abhijeet