Hello, I’m hoping someone can help me be able to post inline comments on PR’s. In the UI version of Bitbucket, you can post a comment on a specific line, for example, line 6. (I’d share a screenshot but apparently new users can only include one media per post.) However, when I try to send a POST request to the API, it won’t do an inline comment. All I can get it to do so far is post the comment at the end, as shown in this screenshot, rather than on a specific line, like line 6:

The POST endpoint I’m using is (https://api.bitbucket.org/2.0/repositories/{workspace}/{repo}/pullrequests/6/comments)
and I’m sending the following information in body:
{
"content": {
"raw": "will this work on one line?"
},
"inline": {
"from": 6,
"to": 7,
"path": "style.css"
}
}
No matter what I put in the “from” and “to” it always puts the comment at the end, like in the screenshot, rather than inline, like it does in the UI. Does anyone have any suggestions for getting the POST request to do inline comments like the UI version allows?
Hi Renee,
It looks like you might be running into a rough edge on this API and our documentation doesn’t make this the easiest to find.
Buried in the documentation for the “Create a comment on a pull request” API (you have to go down to “Body Parameters”, click on the “Comment” link, and then in the popup, click on “inline” to see it) we mention that if you provide both a from
line and a to
line, the to
line is ignored completely.
The comment’s anchor line in the new version of the file. If the ‘from’ line is also provided, this value will be removed.
Looking at your screenshot, it appears that the comment is showing up on “from line” 6, like you specified in the POST body.
Ideally, the API should return a 400 Bad Request response when you provide both from
and to
, but that would have to be a backwards-incompatible breaking change, so we just assume if you provide both, that the from
line is the one you want, which is not always the case.
I hope that helps.
1 Like
Thank you! Yes, that helps.
@ReneePeti I want to comment as a bot how can I do that?
@ReneePeti can I comment as a bot with the same api, I have connect app my jwt token process looks like this:
atlassianJwt.encodeSymmetric(
{
iss: ‘hikaflow-app’,
iat: now.unix(),
exp: now.add(5, ‘minutes’).unix(),
qsh: atlassianJwt.createQueryStringHash(
atlassianJwt.fromMethodAndUrl(method, resource),
),
sub: data.clientKey,
},
installation.sharedSecret,
);
what should I need to change here?