Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Bitbucket Server API: add a file to a repository


3 answers

1 accepted

0 votes
Answer accepted

Hello Daavid and welcome to the Community!

From reviewing your request for the cloud API you want to be mirrored over in server there is an API which you can use on server. The similar REST API endpoint you’re wanting to use is as follows; /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/browse/{path:.*}.

This endpoint will allow for the following;

The file can be updated or created on a new branch. In this case, the sourceBranch parameter should be provided to identify the starting point for the new branch and the branch parameter identifies the branch to create the new commit on.

I hope this information proves helpful and you’re able to upload/add files to Bitbucket server without issue.

Stephen Sifers

Thank you! This is what I needed.

Like Stephen Sifers likes this

@Stephen Sifers i have issue, when i try to use the API you have mentioned above is not working. instead of updating the file content is reading the file. i have added sample curl which i have tried, 

curl --location --request PUT '' \
--header 'Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=' \
--form 'content=test changes' \
--form 'message=Updated using file-edit REST API' \
--form 'branch=development'

Please help me to fix this issue

Hello @arun

The answer above is almost 3 years old, and with Bitbucket Server 7.21 being available, it may no longer apply (As the above reference links to 6.4).

With this said, in Bitbucket Server you could attempt the following endpoint and example:



This API can also be invoked via a user-centric URL when addressing repositories in personal projects.

Update the content of path, on the given repository and branch.

This resource accepts PUT multipart form data, containing the file in a form-field named content.

An example curl request to update '' would be:

 curl -X PUT -u username:password -F  -F 'message=Updated using file-edit REST API'
 -F branch=master -F  sourceCommitId=5636641a50b
  • branch: the branch on which the path should be modified or created
  • content: the full content of the file at path
  • message: the message associated with this change, to be used as the commit message. Or null if the default message should be used.
  • sourceCommitId: the commit ID of the file before it was edited, used to identify if content has changed. Or null if this is a new file

The file can be updated or created on a new branch. In this case, the sourceBranch parameter should be provided to identify the starting point for the new branch and the branch parameter identifies the branch to create the new commit on.

Stephen Sifers

@Stephen Sifers yes i have referred the same doc and tried the same as u have mentioned. You can check the sample curl comment in the above comment.But still instead of updating the content in the file  it’s reading the content from the file what we passed in the path. Is there anything I’m doing wrong here or what could be the issue.

thanks ,

Arun s

Hello @arun 

The only issue I may see is your use of the --location since it seems you're using a proxy server. It may not be possible for your to test without the proxy since it's in place for a reason, but do see if you can test without your proxy.

What I see with -L or --location is the following:

When curl follows a redirect and if the request is a POST, it will send the following request with a GET if the HTTP response was 301, 302, or 303. If the response code was any other 3xx code, curl will re-send the following request using the same unmodified method.

You can tell curl to not change POST requests to GET after a 30x response by using the dedicated options for that: --post301, --post302 and --post303.

The method set with --request overrides the method curl would otherwise select to use.


Stephen Sifers

@Stephen Sifers When u try to use the postman also I’m facing this issue and not just curl.

And have you tried the updating the content of the file any time? It’s working for you?


Interesting, this post is related to a Server version of our product. Can you confirm if you're using a Server or Cloud version of Bitbucket? If server, can you let me know which version you're presently on?

This will help me understand what might be the problem and help me investigate if there is a known issue around this.

Stephen Sifers

@Stephen Sifers yes I’m  using bitbucket server only and version is 7.17.4.


Could you please let us know the following:

  1. What is the response code and JSON response you get back from the endpoint?
  2. Were you able to test without the Proxy in place?
  3. Is POST responding correctly or similar to PUT?

I am unable to find any similar issues which may be causing this and need to understand more.

Stephen Sifers

@Stephen Sifers @Please find below my replay for your questions,

1. I’m getting as 200 response code and the same Json response as GET method

"lines": [
"text": "{"

"text": " \"version\": \"1.0.0\""
"text": "}"
"start": 0,
"size": 39,
"isLastPage": true,
"limit": 500,
"nextPageStart": null

2.I don’t have details of without proxy server but I’m testing the url which will show while accessing the bitbucket on browser

3. For post method also I’m getting the same response as PUT

Thanks ,

Arun S

@Stephen Sifers any updates on this issue? 


Hello @arun 

All signs are pointing to your Bitbucket Server sitting behind a reverse proxy which is converting your POST and PUT calls into a GET. More evidently, the fact you're getting a 200 back as a GET shows that something is interfering with your API call to the endpoints.

Please work with your Admin to test without the proxy and see if the results and consistent. If removing the proxy is not an option for testing, then please work with your admin to ensure the reverse proxy is configured correctly to allow your API Headers to pass through.

Stephen Sifers

@Stephen Sifers I have an issue when I send request that time I receive 415 unsupported media type responses. Content-type(application/json). Basically, I have to create the text file and inside the file send a text.

``` ```

Hello Dinkar,

This post is a bit old so the links are referencing an older version, please see /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/browse/{path:.*} 

The example curl call there is as follows:

 curl -X PUT -u username:password -F  -F 'message=Updated using file-edit REST API'
 -F branch=master -F  sourceCommitId=5636641a50b

Stephen Sifers

Suggest an answer

Log in or Sign up to answer

Atlassian Community Events