Hi, I am trying to do a POST request using the REST node transformation in Data Integration Studio.
I need to pass a body in json format. This is an http post working on PowerShell:
$params = @{ "username"="myusername"; "password"="mypassword"; "site"="cittadini"; "traceId"="23133423429"; "tipo"="richiesta"; "history"="true"; } Invoke-WebRequest -Uri http://localhost:8080/searchDocument/1 -Method POST -Body ($params|ConvertTo-Json) -ContentType "application/json" -OutFile "C:\SAS\TEMP\output.json"
This is how I configured the REST transformation in SAS DI:
HTTP method: POST
HTTP request endpoint: http://localhost:8080/searchDocument/1
HTTP content type: applicatio/json
HTTP charset: utf-8
Input type: text
Input charset: utf-8
Input text:
{
"username": "myusername",
"password": "mypassword",
"site":"cittadini",
"traceId":"23133423429",
"tipo":"richiesta",
"history":"true"
}
Output type: file
I got an error in the response when executing the SAS job:
type Exception report message Request processing failed; nested exception is java.lang.IllegalArgumentException: Invalid token character ' ' in token "json charset=utf-8" description The server encountered an internal error that prevented it from fulfilling this request. exception org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalArgumentException: Invalid token character ' ' in token "json charset=utf-8" org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:656) org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560) javax.servlet.http.HttpServlet.service(HttpServlet.java:650) javax.servlet.http.HttpServlet.service(HttpServlet.java:731) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) root cause java.lang.IllegalArgumentException: Invalid token character ' ' in token "json charset=utf-8" org.springframework.http.MediaType.checkToken(MediaType.java:282) org.springframework.http.MediaType.<init>(MediaType.java:255) org.springframework.http.MediaType.parseMediaType(MediaType.java:584) org.springframework.http.HttpHeaders.getContentType(HttpHeaders.java:286) org.springframework.web.bind.annotation.support.HandlerMethodInvoker.readWithMessageConverters(HandlerMethodInvoker.java:622) org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveRequestBody(HandlerMethodInvoker.java:607) org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveHandlerArguments(HandlerMethodInvoker.java:346) org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:171) org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:427) org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:415) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:788) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:717) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644) org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560) javax.servlet.http.HttpServlet.service(HttpServlet.java:650) javax.servlet.http.HttpServlet.service(HttpServlet.java:731) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
The error message makes me think it is something related to the text body format.
How should I format the json body text in the REST transformation to work properly?
Hello,
Your json body does not appear to be malformed.
By I did notice this:
HTTP content type: applicatio/json
Perhaps changing applicatio/json to application/json might resolve issue?
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.