Search code examples
javaspring-bootpostmanresttemplatespring-resttemplate

RestTemplate GET call gives 422


I am in the process of integrating with a third party app and this issue comes while integrating with one of their GET APIs. The API has some headers and params and it's working perfectly fine in Postman. However, the same request when formed in Java and executed with RestTemplate (exchange method) gives 422 unparsable entity. Where could I be going wrong and what could be done to fix this issue?


Solution

  • It really depends on the server end why it responds with that HTTP code.

    Definition of 422 Unprocessable Entitycode from Mozilla website:

    The HyperText Transfer Protocol (HTTP) 422 Unprocessable Entity response status code indicates that the server understands the content type of the request entity, and the syntax of the request entity is correct, but it was unable to process the contained instructions.

    which means, the data is correct, and server understood it but it cannot process the request.

    I suggested you try in RestTemplate using the same exact values tested successfully on Postman.

    A screenshot on Postman and your some snapshot of your code on the headers and request params will help to debug further. Make sure you don't mistake @PathVariable with @RequestParam.