Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to post html comments on pull request via 2.0 api?

Chen Xinwei April 24, 2019

I'm trying to post comments via bitbucket 2.0 api.

Where the doc can be found here:

https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/pullrequests/%7Bpull_request_id%7D/comments#post

 

However, I get  "content.html": "extra keys not allowed" when I create a json where 

content looks like:

{

     "content“:{

          "raw": "blablablabla",

          "html": "blablablabla"

    }

}

4 answers

1 vote
sam February 18, 2020

@stephen  @Steph @Stephen Siferscould you kindly update us if the html content option really works. Otherwise I could switch to Jira or any other options because this is a big necessity for me. Thanks much @Tim Clipsham

0 votes
Chip Landwehr July 7, 2022

You need to use markup:  https://commonmark.org/help/

Example:

[*BuildFinished* **SOME BUILD**] 186dab06140a into 165d0168b4d3 \n \n[**✓ BUILD SUCCESS**](https://www.somewebsite.com) - Build *#9999* which took *7 min 46 sec* ✕
0 votes
sam February 28, 2020

Seem to not work for me, I am actually thinking of migration to GitHub.

Deleted user February 28, 2020

The only allowed value to send to Bitbucket API is `content.raw`. 

I've tested this 2 minutes ago and it works like charm. Of course your content needs to be formatted as markdown.

sam February 28, 2020

for my case, it works too for the raw and the comment is saved ok. My problem is with html content. How do you do it, because the structure given by the documentation doesn't work. Tried something like

"content": {
     "raw": "Just checking",
     "markup": "markdown",
    "html": "<h4>Just checking</h4>",
    "type": "rendered"
}

As it is on the documentation, but doesn't work. This is very important for my case.

The result for my case is as shown in screenshot below, thanksScreenshot from 2020-02-28 18-55-27.png

sam February 28, 2020

I mean, html is never rendered

Julien Delange February 28, 2020

same here - this is still not working.

Deleted user February 28, 2020

AFAIK it only works with raw data (i.e. markdown). The HTML is rendered on bitbucket side.

Julien Delange February 29, 2020

How the raw data should be sent here then?

I sent a query as follow and got an error "extra keys not allowed".

The API error message does not provide any meaningful error and the documentation does not help in any way. Which is why so many people are asking here.

 

Thanks.

 

"content": {
     "raw": "# Comment",
     "markup": "markdown"
}

Deleted user February 29, 2020

"content": {
     "raw": "# Comment"
}

Like that ;).

Yes, the extra key "markup" is not allowed to be sent to the API endpoint. Thus it needs to be omitted. 

Julien Delange February 29, 2020

ok so the server infers the content type then.

I am wondering how this is possible to have a lack of documentation on this?

Thanks a lot for your answer.

0 votes
Stephen Sifers
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 8, 2019

Hello Chen and welcome to the Community!

When using the REST API to create a comment within a pull request you must ensure your HTML comment is rendered as HTML. Meaning you must ensure that the comment itself is structured using HTML. An example of a test comment would look as follows:

"content": {"raw": "This is a test comment for HTML testing.", "markup": "markdown", "html": "<p>This is a test comment for HTML testing.</p>", "type": "rendered"}

Notice here that the HTML is not plain text and is rendered as HTML itself.

I hope this proves helpful and you’re able to POST your comments to your pull request soon!

Regards,
Stephen Sifers

Andrew July 10, 2019

Hey Stephen, the example seems not working, it stills shows

{
"type": "error",
"error": {
"fields": {
"content.html": "extra keys not allowed",
"content.markup": "extra keys not allowed",
"content.type": "extra keys not allowed"
},
"message": "Bad request"
}
}

jsummers September 18, 2019

your example gives..

 

{"type": "error", "error": {"fields": {"content.html": "extra keys not allowed", "content.markup": "extra keys not allowed", "content.type": "extra keys not allowed"}, "message": "Bad request"}}

 

Can you please post an example that works?

Matt Perkins September 26, 2019

@Stephen Sifers 

I am seeing the same issue as the posters above, and never saw a response.

I am posting the following JSON to

https://api.bitbucket.org/2.0/repositories/<username>/<slug>/pullrequests/<pull_request_id>/comments


:

{
"content": {
"raw": "This is a test comment for HTML testing.",
"markup": "markdown",
"html": "<p>This is a test comment for HTML testing.</p>",
"type": "rendered"
}
}

 

And receiving the following 400 Response:

{
"type": "error",
"error": {
"fields": {
"content.html": "extra keys not allowed",
"content.markup": "extra keys not allowed",
"content.type": "extra keys not allowed"
},
"message": "Bad request"
}
}
Gustavo Delgado September 26, 2019

I have the same issue, so the endpoint rules doesn't represent what the doc says. 

Like # people like this
aphex3k November 13, 2019

Same for me.

Vibhav November 15, 2019

I am facing the same issue.

The json i am sending as payload is:-

{
"content": {
"raw": "Just checking",
"markup": "markdown",
"html": "<p>Just checking</p>",
"type": "rendered"
}
}

I am getting the below output:-

{    "type""error",    "error": {        "fields": {            "content.html""extra keys not allowed",            "content.markup""extra keys not allowed",            "content.type""extra keys not allowed"        },        "message""Bad request"    }}

Satish SA December 13, 2019

the provided solution never worked and no response was provided to the comments

gallantra_devops February 7, 2020

Any news for html comments?

Julien Delange February 22, 2020

+1 here. Any update on this issue? Seems the API is broken for quite some time.

Deleted user February 28, 2020

Try sending only the raw value. Apparently that's how Bitbucket does it on their interface.

 

image.png

Julien Delange February 28, 2020

Do you mind sending the full request to see the other values of your request?

In particular, what do you put for `markup` and `type` attributes?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events