6

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}'
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Cante Ibanez
  • 291
  • 1
  • 3
  • 12
  • 2
    You should read the docs to understand the error: _”The request HTTP method is not appropriate for the targeted resource. For example an HTTP GET to a resource that only accepts an HTTP POST will result in a 405.”_ – evolutionxbox Apr 24 '18 at 17:18
  • 1
    You've linked to the Bitbucket Server API, which indicates that DELETE is a valid method. Are you trying to use that against Bitbucket Cloud (bitbucket.org)? – Jim Redmond Apr 24 '18 at 18:25
  • I am using it for bitbucket server – Cante Ibanez Apr 26 '18 at 15:53
  • 2
    Can you give examples of the exact URL you're trying to issue a DELETE against? It would be even better if you could provide a `curl` example to reproduce the issue – daveruinseverything Apr 28 '18 at 09:42
  • 1
    as Dave says -- what exactly is the URL you are hitting? The body should be irrelevant, I think. – tgdavies May 05 '18 at 02:18
  • i have updated the post with the CURL script that was generated by POSTMAN – Cante Ibanez May 10 '18 at 10:56

2 Answers2

12

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 GETs and POSTs

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!

daveruinseverything
  • 4,775
  • 28
  • 40
0

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'
Adam Hughes
  • 14,601
  • 12
  • 83
  • 122