Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Delete Bitbucket Branch using Rest API in Java

ramachandranp
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 24, 2020

Trying to delete bibucket branch using rest api but always getting 405 or 145 or 500 as response code. Given below code snippet. Please guide!



String endPoint = "BASE_URL/rest/branch-utils/1.0/projects/<PROJECT>/repos/<REPO>/branches";
String requestJson = "{\"name\":\"refs/heads/feature/TEST\",\"dryRun\":\"false\"}";
HttpClient client = HttpClientBuilder.create().build();
HttpPut putRequest = new HttpPut(endPoint);
putRequest.addHeader("accept", "application/json");
putRequest.addHeader(AUTHORIZATION, BASIC + "passwordencrypted");

StringEntity input = new StringEntity(requestJson, StandardCharsets.UTF_8);
input.setContentType("application/json");
putRequest.setEntity(input);

HttpResponse response = client.execute(putRequest);
System.out.println("StatusCode :: " + response.getStatusLine().getStatusCode());

BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent())));
String output;
StringBuffer result = new StringBuffer();
while ((output = br.readLine()) != null) {
result.append(output);
}
System.out.println("FINAL :: " + result.toString());



 

Also tried with Postman, below errors. Any help will be appreciated!

 

{
"errors": [
{
"context": null,
"message": "An error occurred while processing the request. Check the server logs for more information.",
"exceptionName": null
}
]
}

 

0 answers

Suggest an answer

Log in or Sign up to answer