Do you having an API to push the content to BitBucket Repo.

anumantharaja December 23, 2015

I have gone through your Bitbucket API Documentation, i could not found any API to push the content (i.e) data to the Bitbucket Repository either a raw data or an data in encoded(base64) format. Is there is any API to push the content?

8 answers

1 accepted

evzijst
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 6, 2017

Correct. We now have an API for exactly this. You can upload new content to create new commits and branches through that rest API.

zanedev August 13, 2017

Hi @evzijst

How can you delete a file through the api?  That endpoint doesn't accept delete command and I can't find anywhere that does in the documentation..

Like Viacheslav Gagarin likes this
evzijst
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 14, 2017

You delete a file by creating a new commit that doesn't have the file in question. This is modeled after git/hg where you delete a file by creating a new commit that whose tree doesn't contain the path.

It's documented in the "files" parameter:

Bitbucket API_2017-08-14_13-29-32.png

"when the files field contains a file path that does not have a corresponding, identically-named form field, then Bitbucket interprets that as the client wanting to replace the named file with the null set and the file is deleted instead."

zanedev August 14, 2017

Ah thanks should have read a bit further down.  It indeed does work like this.

ferahl September 25, 2018

On the docs there is only a 200 or 404, how do we know if the push had a conflict and we need to do a pull? There seems to be no checksums in the request/response does this just always overwrite a file even if there is a conflict? Thanks

Iain Dooley
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 18, 2020
Like # people like this
Parul Gupta January 19, 2021

Is there a REST API available for commit and push of files and directory.  I referred https://docs.atlassian.com/bitbucket-server/rest/7.9.0/bitbucket-rest.html but dint find.

1 vote
Tim Burns October 7, 2020

I feel like a number of answers here are not clear so I will go through what I had to do.

1. Click on your personal image in https://bitbucket.org and select the "App passwords"

2. Go into the "App passwords" scope and under repositories, select "read" and "write"

3. Create a token and copy it somewhere safe.  You will use this token on the command line to add files

4. Use the API documented on the POST page here: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/src#post

5. Create a random json file with some content in your current working directory named random.json

5. Create the add object API value like this:

curl -u "my-user-acct:${BITBUCKET_SECRET}" "https://api.bitbucket.org/2.0/repositories/my-workspace/my-repository/src" \
-X POST -F random.json=@random.json


Hope this helps. 

1 vote
evzijst
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 23, 2015

No. Pushing new content to a repo is done through pushing, not the API. There is the online editor, but that does not currently have a public API.

evzijst
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 6, 2017
Ileana Cantu April 9, 2018

Erik,

Can you provide an example of what the file parameter is supposed to look like? Do i specify the file name followed by the content? 

Thanks, 
Ileana

1 vote
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 23, 2015

What exactly do you mean by "content (i.e) data"?  The REST API allows you to do commits (and other stuff like pull requests), so I'm not quite sure what you're missing here?

evzijst
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 23, 2015

Technically, the (Cloud) API does not allow one to create new commits.

anumantharaja December 24, 2015

Thanks Nic and Erik.. Actually I searched API to push the content directly to repo.. For ex in github they providing an API to push the content into repo along with commit msg.

evzijst
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 14, 2017
Like Glenn Spies likes this
Digambar_Dinde March 12, 2018

Hello Eric,

I am trying to update the specific file in repository hosted on bitbucket.

In order to use above api do we need authentication? How to do that?

My host url looks like below : git.gio.companyName.com

0 votes
kanavkhurana January 27, 2017

Hey guys!

 

Has there been any movement on this? Even I have a requirement to push new files to Bitbucket via the API. 

adrian wardell February 19, 2017

Any movement on this?  I too am running up against this issue!  I should have thoroughly checked the API before getting as far as I have.  I really hope there is some way to push updates via the API.  Some kind of response would be great.

Julian Lyndon-Smith April 6, 2017

anyone got an answer ? I really need this functionality 

Amrita December 18, 2017

I am also trying to push files to bitbucket via API, I am using postman to test it out and I am getting an html page in response instead of json object. Please let me know if there is a way to push update to bitbucket. Thank you

evzijst
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 4, 2018

Yes, as per: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/src?_ga=2.195921196.1000697523.1515087326-1192929905.1508644378#post

If you're getting an error, then we'd probably need to see what it said before we could tell you what the problem was. Maybe paste a public link to the postman request here? Otherwise maybe send it to us through support@bitbucket.org ?

0 votes
nmakhotkin December 26, 2016

Hi !

I am working on service which will allow you to store cluster configurations in git repositories. So main functional here is to push cluster configuration to the repo without cloning it. I use github and bitbucket as services where user can store configurations. 

But when I've done with github(there is an API for adding a new commit to the repo and pushing files), I stuck with bitbucket, I didn't find any API endpoint that would allow me to push file contents to the repository. Is it still unavailable? Or I can find it somewhere?

Note: I went through downloads API but it is not what I need. 

0 votes
Markus Merzinger April 10, 2016

Hi there!

This is not really an answer, I just want to add that I understand the question.

 

We at LingoHub we provide our customers a possibility to create a file and push it to the branch of their repository.

We do not have the repository of our customers on our application server (I think you understand that this would be a bad idea). So we are not able to use git CLI commands to push files to the repo.
 

The Github API allows us to do so by using the BLOB endpoint: https://developer.github.com/v3/git/blobs/

 

For our customers who are using Bitbucket we are not able to offer this key feature of our application because we haven't found an equivalent endpoint in the Bitbucket API. 

 

 

0 votes
Corentin Méhat
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 8, 2016

Do you mean "a way to push a file with data into the repo" ? This hence is not Bitbucket but git specific, and you should do it like that:

1/(git) Clone your repo
git clone <repo_url>

2/ Navigate where you want, and add the file in the project path

3/(git) Add the file and push it to the main repo.

git add <file_with_data>
git commit -a -m "<message>"
git push

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events