Jordi Puigdellívol
Jordi Puigdellívol

Reputation: 1748

Create issue on bitbucket api

I'm trying to create an issue on bitbucket with title and content, but it fails with the error:

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

However, if I don't send the content, and only the title, it works and the issue is created

Here is the relevant code

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

I've checked the docs but they are not really acurate

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

Any idea?

Edit:
I found out that using the api v1.0 it works, but only the api 2.0 gives that error message

so
POST https://api.bitbucket.org/2.0/repositories/my-user/my-repo/issues
fails but

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

works

Upvotes: 0

Views: 1050

Answers (1)

Sridhar
Sridhar

Reputation: 11786

I got a similar error message while creating an issue using Bitbucket API v2 but in android. After tinkering for a while, I found that it works if you specify content as an object with raw attribute.

In PHP, It would be,

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

In Postman,

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

body as raw with Content-Type : application/json in header.

If you're using Android(for which this I was looking for), you need to post as json using 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>);

Upvotes: 1

Related Questions