Deleting a branch using the API

How do I use the DELETE endpoint of the REST API for branches?

https://developer.atlassian.com/static/rest/bitbucket-server/5.5.0/bitbucket-branch-rest.html

Looking at this, I'm supposed to send a request object with the DELETE, but DELETE doesn't support passing an object?

The endpoint should simply be a request to 

/rest/branch-utils/1.0/projects/{projectKey}/repos/{repositorySlug}/branches?name=somebranch&dryRun=true

 

I don't know how you'll handle the /refs/head/- and forward slashes people use in their requests. But it seems wrong to imply that people should pass an object with their DELETE request.

 

Or do it like a POST request, to a 

/rest/branch-utils/1.0/projects/{projectKey}/repos/{repositorySlug}/delete

With the object, with the name and dryRyn - that would work right out of the box. And the branch-target is inferred by the branch-utils in the beginning of the API.

2 answers

0 vote

Hi Nicolaj,

The delete rest end point requires the ref to be specified as part of the input request, not in the URL itself. 

 

If you expand the "Example request representations", you'll get an example json file:

{
    "name": "refs/heads/my-branch",
    "dryRun": false
}

 

Add this to your request to provide the input file:

-H "Content-Type: application/json" --data @input.json 

 

Cheers,

Caterina

0 vote

how do we do this in postman? I have tried using the example with the json in the 'body' tab of postman and i am getting error 405 :  Method Not Allowed

James Redmond Atlassian Team 2 hours ago

Are you using Bitbucket Server or Bitbucket Cloud? This API is just for BB Server; there is no corresponding endpoint for BB Cloud.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Piotr Plewa
Published Dec 27, 2017 in Bitbucket

Recipe: Deploying AWS Lambda functions with Bitbucket Pipelines

Bitbucket Pipelines helps me manage and automate a number of serverless deployments to AWS Lambda and this is how I do it. I'm building Node.js Lambda functions using node-lambda&nbsp...

2,006 views 1 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you