Reputation: 331
Using postman, I have succeeded in creating branches in bitbucket via their REST API and using the guide below
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}'
Upvotes: 8
Views: 7641
Reputation: 16319
The accepted answer gives the BB 1.0 API request details. In the 2.0 API this is really simple. It's just an empty delete request with no payload to:
DELETE {{BB_API}}/repositories/{workspace}/{reposlug}/refs/branches/{branchname}
So for example if you have repo "myrepo" in project "sandbox", to delete the branch named "test1" you'd do (excluding auth)
curl --location --request DELETE 'https://api.bitbucket.org/2.0/repositories/sandbox/myrepo/refs/branches/test1'
Upvotes: 1
Reputation: 5177
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!
Upvotes: 14