Using postman, I have succeeded in creating branches in bitbucket via their REST API and using the guide below
Bitbucket Rest API Guide
But I cannot delete a branch using the same guide as well.
I have created a JSON and placed it in the body tab of POSTMAN then using DELETE for the HTTP method but no success.
I am getting error 405 - Method Not Allowed, what does that mean? Did my request pushed through but I am not allowed?
Using the bitbucket web UI, I am able to delete and create branches.
Edit:
This is the postman generated CURL
curl -X DELETE https://<url>/rest/api/1.0/projects/<abc>/repos/<xyz>/branches
-H 'authorization: Bearer xxxxxx' -H 'cache-control: no-cache'
-H 'content-type: application/json'
-H 'x-atlassian-token: nocheck'
-d '{"name": "refs/heads/feature/name","dryRun": false}'
In Bitbucket go to branches on the left hand side menu. Select your branch you want to delete. Go to action column, click on three dots (...) and select "delete branch".
Delete BranchClick on the "Branch" button. Click on "Delete Branches" tab. Check the branch or branches you intend to delete. Click on "Delete Branches".
Add a user, check/uncheck the option, remove the user and save. Just a thought/idea, you may want to solve this problem at a lower layer, in `git` you can use an update-hook and simply prevent the deletion. This should live with the repo and protect it where it sits Bitbucket cloud or server.
It looks like you're using the incorrect REST endpoint, one that doesn't accept the DELETE
HTTP verb. The one you're using is:
/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/branches
As per the docs, this endpoint only accepts GET
s and POST
s
Judging by the format of your call, I'm guessing the one you're actually after is this:
/rest/branch-utils/1.0/projects/{projectKey}/repos/{repositorySlug}/branches
The branch-utils API docs describe more or less the exact payload you're trying to use.
Digging a little deeper and I believe this mistake isn't your fault. The Bitbucket branch util docs for Bitbucket 5.8 and below show the correct URL path, but for 5.9 and up the path seems to be missing.
Full disclosure: I work for Atlassian. That being the case I'll chase this up and have it corrected :)
Edit: the docs have since been fixed!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With