0

Spring RestTemplate request to Acumatica REST API Customer not working when customer id is having ampersand in between customer id sent in the request

I even tried replacing & with %26 as givne below and its working in Postman tool but not working when tried from Spring application using RestTemplate Object

The Url working in Post man and not working in my Spring Application using RestTemplate Object is https://acumatica.kimballinc.com/AcumaticaERP/entity/sprestprod/6.00.001/Customer?$filter=CustomerID eq 'WESTECH FUEL %26 EQUIP'&$expand=MainContact/Address,ShippingContact/Address

Java Spring Application code used is

HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.add("authorization", "Bearer iuwnsne9383nx,sowejwew");
HttpEntity<String> header = new HttpEntity<String>(headers);
RestTemplate restTemplate = new RestTemplate();
String url = "https://acumatica.kimballinc.com/AcumaticaERP/entity/sprestprod/6.00.001/Customer?$filter=CustomerID eq 'WESTECH FUEL %26 EQUIP'&$expand=MainContact/Address,ShippingContact/Address"
restTemplate.exchange(url, HttpMethod.GET, header, AcumaticaCustomerVO[].class);
venkat
  • 39
  • 1
  • 8
  • I'll be looking at your case later today, I believe the issue is spring RestTemplate related. Perhaps another method can be used like URI: https://stackoverflow.com/a/56027025/7376238 – Hugues Beauséjour Dec 03 '19 at 15:48
  • The key part seems to be: Do not pass encoded url string as parameter to RestTemplate.exchange() – Hugues Beauséjour Dec 03 '19 at 15:49

1 Answers1

0

I believe RestTemplate is messing with the URL encoding scheme.

There appears to be workarounds:

  1. Adding StringHttpMessageConverter to the template's message converters: https://stackoverflow.com/a/28742831/7376238

  2. Avoid the RestTemplate exchange call and use UriComponentsBuilder to construct URI instead: https://stackoverflow.com/a/56027025/7376238

Hugues Beauséjour
  • 8,067
  • 1
  • 9
  • 22