Failed to parse response of REST API

Failed to parse response of REST API

  

Hi All,

I am getting the following error when I try to process the response of a REST API


Failed to parse response of  REST API

Parsing '': Unexpected character encountered while parsing value: E. Path '', line 0, position 0.


I am getting this error once in  a day not everytime. The REST API I am using gives a JSON response and I am just processing it.


What is the reason for this error and how can I eradicate it?







Ananth wrote:

Hi All,

I am getting the following error when I try to process the response of a REST API


Failed to parse response of  REST API

Parsing '': Unexpected character encountered while parsing value: E. Path '', line 0, position 0.


I am getting this error once in  a day not everytime. The REST API I am using gives a JSON response and I am just processing it.


What is the reason for this error and how can I eradicate it?








Your JSON might be Invalid.
Please check the response json through LOG.

Ananth wrote:

Hi All,

I am getting the following error when I try to process the response of a REST API


Failed to parse response of  REST API

Parsing '': Unexpected character encountered while parsing value: E. Path '', line 0, position 0.


I am getting this error once in  a day not everytime. The REST API I am using gives a JSON response and I am just processing it.


What is the reason for this error and how can I eradicate it?







We often get this kind of error when the response json is not according to the structure that we take. Or it might be invalid as asif told. Check the response of that json.

Sachin 

Sachin Mahawar wrote:

Ananth wrote:

Hi All,

I am getting the following error when I try to process the response of a REST API


Failed to parse response of  REST API

Parsing '': Unexpected character encountered while parsing value: E. Path '', line 0, position 0.


I am getting this error once in  a day not everytime. The REST API I am using gives a JSON response and I am just processing it.


What is the reason for this error and how can I eradicate it?







We often get this kind of error when the response json is not according to the structure that we take. Or it might be invalid as asif told. Check the response of that json.

Sachin 

Hi Sachin,

If the Json response is invalid, I should get the error everytime when I am requesting the REST API. But I am not getting the error all the time.


Hello Ananth, 

Usually this error happens when the answer is not a valid JSON (like no JSON at all, due invalid authorization or just because the server did not find anything).
This can happen for many number of reasons, so it's possible to happen even if most of the time the server still returns a valid response.

Without knowing the specification of the web service you're consuming is hard to tell anything, but you can take a look here:

https://success.outsystems.com/Documentation/10/Extensibility_and_Integration/REST/Troubleshoot_a_REST_API

And also here:

https://success.outsystems.com/Documentation/10/Extensibility_and_Integration/REST/Consume_REST_APIs/Handling_REST_Errors

This should give you an idea on how to handle errors returned by the web service being consumed and also how to increase the logging level so that you can take a look in the answer you are receiving, so that you can understand what is going on.

Cheers.

Ananth wrote:

Sachin Mahawar wrote:

Ananth wrote:

Hi All,

I am getting the following error when I try to process the response of a REST API


Failed to parse response of  REST API

Parsing '': Unexpected character encountered while parsing value: E. Path '', line 0, position 0.


I am getting this error once in  a day not everytime. The REST API I am using gives a JSON response and I am just processing it.


What is the reason for this error and how can I eradicate it?







We often get this kind of error when the response json is not according to the structure that we take. Or it might be invalid as asif told. Check the response of that json.

Sachin 

Hi Sachin,

If the Json response is invalid, I should get the error everytime when I am requesting the REST API. But I am not getting the error all the time.


Then I would recommend you to put a log and analyse both the json wrong vs correct one. 

Sachin


I'm going to plug my old short post about setting the log level of a REST API.

As for why only sometimes this happens, I've seen REST implementations that return text/plain instead of text/json with a plain text error message in case of wrong data or some other problem. So it needn't be the case that it would always fail.

Hi Ananth ,

Try to run the API first by any API testing tool like Postman and see what response you are getting back from API.

Also you can copy and paste the API response from postman in any JSON format tool to check what exactly causing issue.

Also while consuming JSON API you can add OnResponse method to debug more.


Regards

-PJ-