BookmarkSubscribeRSS Feed
lfabbri
Obsidian | Level 7

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?

 

 

1 REPLY 1
ChrisLysholm
SAS Employee

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?

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to connect to databases in SAS Viya

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.

Discussion stats
  • 1 reply
  • 1493 views
  • 0 likes
  • 2 in conversation