How to @ mention users in Pull Request comments through the Bitbucket Cloud Rest API
Platform Notice: Cloud Only - This article only applies to Atlassian products on the cloud platform.
Summary
The Bitbucket Cloud Rest API allows users to add comments to a Pull Request. To add comments "@" mentioning other users, this can easily be achieved through the UI and the current API documentation does not list an example of how to achieve this through an API call;
Solution
Pull Requests' comments indexes users for "@" mentions using their Atlassian Accounts' IDs, so in this case, in order to be able to mention a user through the Rest API, you will need to find that user's Atlassian Account ID first. This can be achieved through the members' API endpoint:
1
$ curl -X GET -u <username>:<apppassword> 'https://api.bitbucket.org/2.0/workspaces/<workspace>/members'
Once you found the desired user and retrieved their Atlassian Account ID, the following syntax can be used to "@" mention this user through the API in a comment:
1
$ curl -X POST -u <username>:<apppassword> 'https://api.bitbucket.org/2.0/repositories/<workspace>/<repository>/pullrequests/<id>/comments/' -H "Content-Type: application/json" -d '{"content":{"raw":"Hi @{<AID>} "}}'
Was this helpful?