https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/src#post
I have tried to write the file using API but it always write file in the master branch. I need to write in some other branch. I tried query string ?branch=branch_name but its not working.