Unable to make post call using spring restTemplate with gitlab api
I am trying to create a Merge Request using API and spring RestTemplate. But ending up with an error below.
org.springframework.web.client.HttpClientErrorException$Conflict: 409 Conflict OR org.springframework.web.client.HttpClientErrorException$BadRequest: 400 Bad Request
Below the the code
String url = "https://gitlab.xxxx.com/api/v4/projects/12345/merge_requests";
RestTemplate restTemplate = new RestTemplate();
MergeBranchRequest mergeBranchRequest = new MergeBranchRequest(); //mergeBranchRequest.setId("1"); mergeBranchRequest.setSource_branch(srouceBranchName); mergeBranchRequest.setTarget_branch(targetBranchName); mergeBranchRequest.setTitle(mergeTitle);
List mediaType = new ArrayList(); mediaType.add(MediaType.ALL);
HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); headers.setAccept(mediaType); headers.add("PRIVATE-TOKEN", "xxxxxxxxxxx");
HttpEntity requestEntity = new HttpEntity(mergeBranchRequest, headers); ResponseEntity s = restTemplate.exchange(uri, HttpMethod.POST, requestEntity, String.class); s.getBody();