Rest Template POST returning Bad Request

I am trying to get an auth token from a server using RestTemplate in Spring. However, I am getting a 400 bad Request. I understand that this is an issue in the parameters that i am sending in my request. I am able to successfully get the token using postman:
enter image description here

Content-Type is application/json

This is the code I am using for the request:

RestTemplate restTemplate = new RestTemplate();
        HttpHeaders headers = new HttpHeaders();

        OauthRequestUtil oauthRequest = new OauthRequestUtil();

            HttpEntity<OauthRequestUtil> request = new HttpEntity<>(oauthRequest, headers);
            ResponseEntity<String> response =, HttpMethod.POST, request, String.class);

I am getting the 400 error on the line. The param values are correct, they are lifted straight from postman.

OauthRequestUtil is just a class with the private variables and getters/setters

public class OauthRequestUtil {

    private String clientId;
    private String clientSecret;
    private String grant_type;
    private String resource;

Leave a Reply

Notify of