2017-09-03 83 views
0

我試圖創建與標題和內容到位桶的問題創建問題,但它與錯誤失敗:上到位桶API

{"type": "error", "error": {"fields": {"content": "expected a dictionary"}, "message": "Bad request"}} 

但是,如果我不發送content,只有在title,它的工作原理,並在創建問題

下面是相關代碼

$response = $this->getClient()->post(static::URL . "/repositories/{$repository}/issues", [ 
     "body" => [ 
      "title"  => "a title", 
      "content" => "the issue body 
     ] 
    ]); 

我已經檢查了文檔,但他們是不是真的acurate的

https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/issues

任何想法?

編輯:
我發現,通過使用該API V1.0它的工作原理,但只有API 2.0給出了錯誤信息

所以
POST https://api.bitbucket.org/2.0/repositories/my-user/my-repo/issues
失敗,但

POST https://api.bitbucket.org/1.0/repositories/my-user/my-repo/issues

作品

+0

什麼是你想發送在你的問題的內容發佈爲json?它的工作對我很好 –

+0

@VuralAcar一個簡單的字符串失敗「內容」=>「問題體」 –

+0

我發現用api 1.0的作品,但是2.0不是 –

回答

0

我在使用Bitbucket API v2創建問題時遇到了類似的錯誤消息,但在android。經過一段時間的修改之後,我發現它的工作原理是,如果將content指定爲具有raw屬性的對象。

在PHP中,這將是,

$response = $this->getClient()->post(static::URL . "/repositories/{$repository}/issues", [ 
     "body" => [ 
      "title"  => "a title", 
      "content" => [ 
       "raw" => "the issue body" 
      ] 
     ] 
    ]); 

在郵差,

{ 
    "title":"title of the issue", 
    "content":{ 
     "raw":"this should be the description" 
    } 
} 

體如raw與頭Content-Type : application/json

如果你使用的是Android(對於此我一直在尋找),您需要使用JsonObjectRequest

JSONObject body = new JSONObject(); 
body.put("title", "title of the issue"); 

JSONObject content = new JSONObject(); 
content.put("raw", "this should be the description"); 

body.put("content", content); 

JsonObjectRequest stringRequest = new JsonObjectRequest(<url>, body, <Response listener>, <Error Listener>);