How to enclose file to pull request comment via REST API in Bitbucket Server/DataCenter

Still need help?

The Atlassian Community is here for you.

Ask the community

For Atlassian eyes only

This article is Not Validated and cannot be shared with customers.

Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.

Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible


Bitbucket Server pull request comments allow to enclose file(s) from local drive (via Bitbucket Server UI) and in this Knowledge Base Article we will be demonstrating how to enclose file to pull request comment via REST API.


Bitbucket Server and DataCenter version 7.16+


Create a file

foo A
foo B
foo C

Add file as attachment

curl -k -u admin:admin \
     -X POST 'http://localhost:7990/projects/{projectKey}/repos/{repositorySlug}/attachments' \
     -H 'Content-Type: multipart/form-data' \
     -F 'files=@foo.txt'

As a response, you should expect below. Please take note of the attachment value in the response text as you will need it for the next API command. For example, the attachment value for the response text below is 1/3.

Sample response

Add comment to pull-request, referring attachment in comment's message

Execute another API command to add a comment (with attachment) to a pull-request with the attachment value received from the previous API command. For example, the attachment value to add is 1/3.

curl -k -u admin:admin \
     -H 'Content-type: application/json' \
     -X POST 'http://localhost:7990/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pullRequestId}/comments' \
     -d '{"text": "From Local Drive - [foo.txt](attachment:1/3)"}'

As a response, you should expect:

Sample response
	"text":"From Local Drive - [foo.txt](attachment:1/1)",



If you find any issue with the API call, please reach out to Bitbucket support.

Last modified on Oct 7, 2022

Was this helpful?

Provide feedback about this article
Powered by Confluence and Scroll Viewport.