上到位桶API

问题描述:

我试图创建与标题和内容到位桶的问题创建问题,但它与错误失败:上到位桶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不是 –

我在使用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>);