Error in Calling Rest service action

0
I am calling a rest service in my microflow  and i receive an error  (error parsing json) ‘Error parsing JSON. Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')  at [Source: (org.apache.http.conn.EofSensorInputStream); line: 1, column: 2]     at Main.CallJAVaAction (CallRest : 'Call REST (GET)')Error parsing JSON. Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')  at [Source: (org.apache.http.conn.EofSensorInputStream); line: 1, column: 2]     at Main.CallJAVaAction (CallRest : 'Call REST (GET)')’.   How do I resolve this error?
asked
2 answers
1

I’m assuming you didn't make any obvious errors while modelling, and this is a well developed REST service. In my experience, when you get an error like this, it’s because the service responds with an HTML document, which you cannot parse using an import mapping.

The first thing to check is the response code (which you can usually find in $latestHttpResponse/StatusCode). If it’s in the 400 range, the error is on your side. If it’s in the 500 range, the error is on the side of the REST service and you should contact them.

Furthermore, I would set the log level of the REST Consume node to trace, to see the entire response, and see if there is a hint on how to resolve the error there. If there is no hint, you should contact the developer of the service.

answered
1

Hey Ishani,

It looks like your rest service may not be receiving the correct format. I get this error sometimes when I’ve set the REST service action in Mendix to receive JSON, but the service is returning the data in XML format. So you’re problem could be in potentially two different places:

  1. You could be sending the data in the wrong format in the actual service.
  1. You could be receiving the data in the wrong format in Mendix.

 

So, the first thing I’d do is add an ‘Accept’ header into the REST action (Under the header tab). So you’d add ‘Accept’ as the key, and the value in this case would be ‘application/json’. Generally, when the rest action is giving me your error, adding that header fixes it.


However, in the case that this doesn’t fix your problem, you may want to check into the service. It looks like your rest action is currently trying to receive a XML response. If the adding the above header doesn’t fix your problem, you may need to update your structure to an XML format rather than JSON.

answered