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

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

Avatar

1 badge earned

Collect

Participate in fun challenges

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

Challenges
Coins

Gift kudos to your peers

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

Recognition
Ribbon

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!

Leaderboard

Creating a commit through API ignore query params

Hi!
I'm trying to create a commit using this API: Create a commit uploading file API 
I need to create the commit on a specific branch because push on master is locked.

 

This is my request

POST /2.0/repositories/myworksp/myrepo/src?branch=chore%2Fupdate-file&message=Updated+file.yml&files=file.yml HTTP/1.1
Accept: application/json, text/plain, */*
Content-Type: multipart/form-data; boundary=--------------------------487458948671530879406796
Authorization: Bearer theT0k3n
User-Agent: axios/1.2.1
Accept-Encoding: gzip, compress, deflate, br
Host: api.bitbucket.org
Connection: close
Transfer-Encoding: chunked


As described in docs, I set `branch` query param to set branch, but the error "Push is locked on master branch" is always returned.

Do I need to set the branch name in a different way?

 

P.S. If I make the request in a non-restricted repo the commit is correctly created on master branch of that repo

1 answer

1 accepted

0 votes
Answer accepted
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
Dec 16, 2022

Hi @Samuele Salvatico and welcome to the community!

If you want to create a commit that adds or updates a file, you can use a call like the following:

curl -X POST -u username:app-password https://api.bitbucket.org/2.0/repositories/workspace-id/repo-slug/src -F myFile.json=@myFile.json -F branch=test-branch -F message="my commit message"

If you want to create a commit that deletes a file you can use the files parameter as follows:

curl -X POST -u username:app-password https://api.bitbucket.org/2.0/repositories/workspace-id/repo-slug/src -F files=myFile.json -F branch=test-branch -F message="my commit message"

Kind regards,
Theodora

Any idea why CURL works but not Python's requests? The file gets uploaded but the params are ignored (commits to master branch and doesn't use the right commit message)

 

Python Code:

response = requests.post(
            headers={
                "Authorization": f"Bearer {token['access_token']}"
            },
            files = {
                'README.md' : ('README.md', f),
                'message': "my commit message",
                'branch': 'defect/referencechanges'
            }
        )
CURL:
curl -H "Authorization:Bearer xxxxxx" -X POST https://api.bitbucket.org/2.0/repositories/xxxxxx/xxxxxxx/src -F README.md=@README.md -F branch=defect/referencechanges -F message="my commit message"

Nvm, figured it out.

 

response = requests.post(
            headers={
                "Authorization": f"Bearer {token['access_token']}"
            },
            files = {
                'README.md' : ('README.md', f),
                'message': ('', "README.md edited via API for testing"),
                'branch': ('', branch)
            },
        )

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events