17

Using REST API 1.0, I can do the following

POST /api/1.0/repositories/{owner}/{repo}/pullrequests/1/comments

What is the equivalent of this in 2.0? 2.0 documentation for pullrequests resource states "Finally, you can use this resource to manage the comments on a pull request as well." I don't see a POST for comments similar to 1.0 companion; nor does PUT do anything about comments.

Is posting comments on a PR supported in 2.0?

WiSeeker
  • 812
  • 9
  • 24

3 Answers3

12

I know it has been quite a long time since the question was asked, but for people coming to this post:

Bitbucket finally added a way to post comments using their 2.0 API. You check the documentation for more info.

And here is an example:

curl -X POST -d '{"content": { "raw": "your comment" }}' $URL
Savas Vedova
  • 5,622
  • 2
  • 28
  • 44
  • 1
    Note that, when this question was asked, "Bitbucket" only referred to the cloud product (bitbucket.org). Now there's also Bitbucket Server, fka Stash, which has a different API (tied to the BB Server version). – Jim Redmond Sep 24 '19 at 21:18
  • True, I am referring to the cloud in this case. Thanks for pointing out @JimRedmond. – Savas Vedova Sep 25 '19 at 07:16
  • 4
    This worked for me after adding this to the headers: `Content-Type: application/json` – ebeezer Apr 07 '20 at 00:07
  • The url should be: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/pullrequests or https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/pullrequests/%7Bpull_request_id%7D/comments#post – Chau Giang Jul 22 '21 at 15:12
4

Unfortunately pull request comments are currently read-only in 2.0. We are definitely keen to finish that API, but these efforts have been rather under prioritized.

For now, 1.0 remains the only way to mutate PR comments.

Also see: https://answers.atlassian.com/questions/32977327/are-you-planning-on-offering-an-update-pull-request-comment-api

Erik van Zijst
  • 2,282
  • 2
  • 17
  • 14
1

First you need to get pull request id using this command :

curl -s --request GET --url '{bitbucket_url}/rest/api/1.0/projects/{project_key}/repos/{repo_key}/pull-requests?State=OPEN&at=refs/heads/'${BranchName}'&direction=OUTGOING' --header 'Content-Type: application/json' -H 'Authorization:Basic {bitbucket_authentication_token}' | sed -n 's/.*"values":\[{"id":\([0-9]*\).*/\1/p'

And then add the comment using this command :

curl --request POST '{bitbucket_url}/rest/api/1.0/projects/{project_key}/repos/{repo_key}/pull-requests/{pull_request_id}/comments' --header 'Content-Type: application/json' -d {"text": "Add your comment here"} -H 'Authorization:Basic {bitbucket_authentication_token}'
Stefan
  • 160
  • 1
  • 11