Sophos Token Request API Error

Hi,

I am trying to generate the token using the URL "id.sophos.com/.../token" as a POST method. I got a successful result when requesting it with the POSTMAN tool. But when I request the same using java API it gives me  "400 BAD REQUEST: "{"errorCode": "customer.validation", "message": "Bad Request"}.

I tried to request the parameters mentioned above in both encoded and non-encoded formats. It gives me the same error. Apart from that the same parameter I used in the python application also, There I got a successful result. I didn't know what is wrong with the java API.

HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
Map<String, Object> requestBody = new HashMap<>();
String apiUrl = "">id.sophos.com/.../token";
requestBody.put("grant_type", "client_credentials");
requestBody.put("scope", "token");
requestBody.put("client_secret", "xxxxxxxxxxx");
requestBody.put("client_id", "xxxxxxxxxxxxx");
URI uri = UriComponentsBuilder.fromHttpUrl(apiUrl).build().toUri();
HttpEntity<?> requestEntity = new HttpEntity<>(mapper.writeValueAsString(requestBody), headers);
ResponseEntity<String> exchange = restTemplate.exchange(uri, HttpMethod.POST, requestEntity, String.class);

since it is Https did we need to add anything  else?

Can u guys give me a response on this?



Added java code
[edited by: Jinto Varghese at 3:10 PM (GMT -7) on 14 Sep 2022]