Bitbucket file update via API

Hello! I’m new to bitbucket (and git in general) and i’m attempting to update an existing file using this API via a java application:

https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/{username}/{repo_slug}/src#post

I’m having some trouble understanding exactly what i need to provide since the documentation is a little unclear to me. Could someone explain what is expected in the “files” and “parents” parameters in what i presume is the payload? Am i supposed to specify a file path or the actual content of the file? If the content, then where would I specify the file name that i’m trying to update?

Thank you!

Hi @ileana.cantu2012 - are you using the API because you’re writing an application to use Bitbucket, or are you just trying to push your code up?

Hi ehenry! I’m using it because I have an application (gui) that needs the ability to change a file in the repo when a user updates certain things.

Hi @ileana.cantu2012, it seems that you’re trying to use a java app which interacts with Bitbucket? I’m not sure if this will help, but to modify a file via our api you can use the following example (but changing the auth):

$ curl -s -H "Authorization: Basic AUTH_TOKEN" -X GET "https://api.bitbucket.org/2.0/repositories/seanfarley/test-hg-subrepo/src/default/default" > foo 
$ echo default >> foo
$ curl -s -H "Authorization: Basic AUTH_TOKEN" -X POST "https://api.bitbucket.org/2.0/repositories/seanfarley/test-hg-subrepo/src" -F /default=@foo

You can see the output of that here: https://bitbucket.org/seanfarley/test-hg-subrepo/commits/354d47270aba95ecf83bceae2b891aabfe2174e1?at=default

But I suspect that your question is more about this third-party app? I’m not sure but let me know if that helps.

Thanks, any idea how we can pass along the last known commit hash (and get a 409 conflict if there has been an update on it)? Updating the file isn’t very useful without that! Also I hope this response returns the updated SHA for future commits but I fear it doesn’t?