Good Morning Outsystems Community,
I am consuming a RestAPI Method from Opentext Content Server. The issue I am facing is unable to parse the response of the method because unable to convert value {null} to the data type of Outsystems.
How do I handle the conversion of NULL values to the data types (such as text, integer, datetime) provided by Outsystems?
Hi, explore this:
https://success.outsystems.com/documentation/11/extensibility_and_integration/rest/consume_rest_apis/simple_customizations/
1. on the callback OnAfterResponse, just replace NULL wilth json arrays, like []
2. that's it!
just try.
thanks
Hi @ibox , thanks for replying.
Sorry, but how do I replace NULL wilth json arrays, like [] as you mentioned?
just use the built in function CustomizedResponse = replace(Response,"NULL","[]")
hi that's it!
good luck!
Morning @ibox ,
Sorry for the late reply!
Thank you for the help managed to replace [null] to [] for my API response.
Regards,
Wai Tin
Hi @Chow Wai Tin
Could you please share the response's screenshot or api link so that will be able check the response. and how to fix it?
Prince
Hello, @Prince Aadil Khan Panwar , thanks for replying
Sorry i can't provide a screenshot of the whole response and can only share part of it.
The error is because unable to parse the below:
"category_id": null
into the Outsystems Data Structure
"category_id": [] (Data Type: Integer List)
do one thing, whenever you test the api in outsystems first click on test and after doing this click on copy to response, after doing this it will copy the response as output in the action which you have created, by that you will be able to see what kind of data type of category id. and then you can check accordingly, whether its text,integer.
Hello @Chow Wai Tin ,
In outsystems if the API response contain null values then field will not generate in the response structure of the API in outsystems .For that u can pass some value instead of NULL value in the response which you are getting.
Hope this will help u .
Thanks and regards
Hello @Asiyah Munawwar , thanks for replying
Yes, I realised that after checking but facing the issue when my Outsystems Data Structure is an Integer List
Create one dummy integer list with some values and on OnAfterResponse action append the dummy list to your structure list
Hope this will helps u.
I simply created a common function called IsNullOrEmpty. Inside it, I check the value of the passed Text using the Length() function. If it equals 0 or any exception is raised, I return True; otherwise, I return False. This is a safe way to check, and then you just need to call this function. If it is NULL or an empty string, you just need to convert it to the desired data format.
With this function, instead of having to handle the processing directly within the OnAfterResponse callback, you can safely implement it for each API that you desire without affecting the entire API consuming process.