102
Views
11
Comments
Solved
How to Convert Null Values received from API Response?

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?

2025-01-09 14-56-57
IQ78
Solution

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 


UserImage.jpg
Chow Wai Tin

Hi @ibox , thanks for replying.


Sorry, but how do I replace NULL wilth json arrays, like [] as you mentioned?

2025-01-09 14-56-57
IQ78
Solution

just use the built in function CustomizedResponse = replace(Response,"NULL","[]")


hi that's it!

good luck!

UserImage.jpg
Chow Wai Tin

Morning @ibox ,

Sorry for the late reply!

Thank you for the help managed to replace [null] to [] for my API response.

Regards,

Wai Tin

2025-01-09 14-56-57
IQ78
Solution

just use the built in function CustomizedResponse = replace(Response,"NULL","[]")


hi that's it!

good luck!

2024-05-08 06-29-37
Prince Aadil Khan Panwar

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?

Regards,

Prince

UserImage.jpg
Chow Wai Tin

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)

2024-05-08 06-29-37
Prince Aadil Khan Panwar

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. 

2023-10-27 12-06-14
Asiyah Munawwar

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


UserImage.jpg
Chow Wai Tin

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

2023-10-27 12-06-14
Asiyah Munawwar

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.

2025-01-09 14-56-57
IQ78
Solution

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 


UserImage.jpg
Chow Wai Tin

Hi @ibox , thanks for replying.


Sorry, but how do I replace NULL wilth json arrays, like [] as you mentioned?

2025-01-09 14-56-57
IQ78
Solution

just use the built in function CustomizedResponse = replace(Response,"NULL","[]")


hi that's it!

good luck!

UserImage.jpg
Chow Wai Tin

Morning @ibox ,

Sorry for the late reply!

Thank you for the help managed to replace [null] to [] for my API response.

Regards,

Wai Tin

2024-02-22 15-41-45
Trương A Xin

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.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.