【问题标题】:Create issue on bitbucket api在 bitbucket api 上创建问题
【发布时间】:2017-09-03 19:29:52
【问题描述】:

我正在尝试使用标题和内容在 bitbucket 上创建问题,但它失败并出现错误:

{"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
        ]
    ]);

我已经检查了文档,但它们并不准确

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

作品

【问题讨论】:

  • 您想在问题中发送什么内容?它对我来说工作正常
  • @VuralAcar 一个简单的字符串失败了 "content" => "the issue body"
  • 我发现 api 1.0 可以,但是 2.0 不行
  • @JordiPuigdellívol 你有没有用 v2 解决过这个问题?我被困在同样的问题上。描述不起作用,内容给了我与上述相同的错误。
  • 没有..刚用v1

标签: php bitbucket guzzle


【解决方案1】:

我在使用 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(我一直在寻找它),您需要使用 JsonObjectRequestjson 发帖

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>);

【讨论】:

    猜你喜欢
    • 2020-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-29
    • 1970-01-01
    • 2012-10-20
    相关资源
    最近更新 更多