How to make Markdown/HTML comment to Bitbucket Pull Request via API?

Viewed 1963

I'm using Bitbucket API (2.0) to submit comments to Pull Rrequests but I'm having a hard time figuring out how to send "styled" comments either using Markdown or HTML.

I've only managed to send comments in raw mode so far.

This is the documentation

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

This is the code that sends raw messages:


BITBUCKET_API_ROOT="https://api.bitbucket.org/2.0"
BITBUCKET_STATUS_API="$BITBUCKET_API_ROOT/repositories/$BITBUCKET_NAMESPACE/$BITBUCKET_REPOSITORY/pullrequests/$PR_ID/comments"


MESSAGE="this is my message."

echo "Pushing comment to $BITBUCKET_STATUS_API..."
curl --request POST $BITBUCKET_STATUS_API \
--user $BITBUCKET_USERNAME:$BITBUCKET_ACCESS_TOKEN \
--header "Content-Type:application/json" \
--silent \
--data "{\"content\": { \"raw\": \"$MESSAGE\" }}"

Trying to specify markdown, this way:

--data "{\"content\": { \"raw\": \"$MESSAGE\", \"markup\": \"markdown\"  }}"

results in:

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

Trying other things, like specifying the html field also didn't help.

1 Answers

I'm pretty sure it's an error in documentation. You can check request they send when someone comment PR. They send data: --data '{"content":{"raw":"test **2**"}}'. And you can check in response what renderer was used to parse your message.
So just send raw message with markdown in it and Bitbucket will use markdown renderer to show it.
And you can find bunch of questions on community.atlassian.com like these ones:
https://community.atlassian.com/t5/Bitbucket-questions/Is-it-possible-to-reply-to-a-pull-request-comment-via-Bitbucket/qaq-p/1047943
https://community.atlassian.com/t5/Bitbucket-questions/How-to-post-html-comments-on-pull-request-via-2-0-api/qaq-p/1066809
They all are without answers from Atlassian.

Related