I am using Outsystems 10 and trying to consume a REST API (single method)
I have copied and pasted the REST Request and Response JSON definitions into the Request and Response text boxes provided by OS REST API. I used the "TEST" button to validate if it was working - I received a 200 OK message. When I closed the dialog - Oustystems automatically created the Request and Response objects.
When I invoke the same REST method through the UI, it is raising a parsing error.
I switched to returning a JSON String and then Deserialize the JSON String, it still raises an error "Failed to parse response of the method 'APIItemSearch' of the 'Enterprise' REST API:
Parsing '': Unexpected character encountered while parsing value: <. Path '', line 0, position 0."
Any ideas on how to resolve this issue?
REQUESTS OBJECT
{
"CountryCode":"US",
"SearchString":"Ford Escape"
}
RESPONSE OBJECT
"Options":[
"Field1":0,
"Field2":0,
],
"SearchStringUsed":"String",
"CountriesFound":[
"Key":"String",
"Description":"String",
"Count":0
"ModelYearsFound":[
"MakesFound":[
"ModelsFound":[
"MatchedCriteria":"String",
"NotMatchedCriteria":"String",
"IsNotExactMatch":false,
"ResponseStatus":{
"ErrorCode":"String",
"Message":"String",
"StackTrace":"String",
"Errors":[
"FieldName":"String",
"Meta":{
"String":"String"
Hi Kilian, Assif and EduardoI was able to resolve the issue. I had forgotten to append "?format=json" at the end of the REST url. So it was returning a HTML doc instead of a JSON object.Regarding the "," in the JSON - I had edited the Correct JSON to simplify the number of fields (50).I want to thank you all for helping me - I appreciate your help.Thank you.
Ravi Subbarao wrote:
Happy to know... You Resolve :)
Keep Coding..
Cheers,
Assif
Hi Ravi Subbarao
I also have the same error when consuming rest API. But I can not use your way to solve my problem.
Is there another way to check row json data if I fetch data from other Sources?
Thanks
Aron Yang wrote:
Hi Aron,
Can you share you JSON data?
both req and response would be much helpful.
Dhiraj Manwani wrote:
Hi Dhiraj Manwani
I add another new post for more detail information including json data. https://www.outsystems.com/forums/discussion/53361/parsing-error-when-consuming-rest-api-on-mobile-app/#Post199737
Could you help to take a look?
BR,
Aron
Hi Ravi,
Very likely you are getting a HTML error page as response, given that the complaint is about a "<" at the very first position. I would like to suggest to turn on the debug logging for your REST service, and check in Service Center what's really sent and received.
I think the only problem is the comma after "Field2:0", not sure what else would be wrong. But as I already said, the error indicates something else alltogether, so my advise stands.
Sorry, but I see commas everywhere? My go-to validator is here, and it shows only that one error I already spotted with my bare eye.
Hi Ravi Subbarao,
The Entire JSON will be Valid If you only correct additional comma.
Ref: https://codebeautify.org/jsonvalidator
Hope it helps,
It seems Assif agrees with me, Eduardo :).
However, again, that has nothing to do with Ravi's original question, as that syntax error in the JSON will be picked up by Service Studio, so I'm sure Ravi just copy/pasted parts of a larger JSON. In the error message, it clearly states there a "<" in the respons at the first position, and that's very common in case there's some error that makes the web server send an HTML error page instead of JSON.