Handling API response when object may or may not be available in response

Hi all,

I’m using UiPath HTTP API activities for scraping some data.

The API I’m currently working with will not always return the same structure. For example, in about 5% of the cases, a specific property (let’s say “date”) may not be available.

So sometimes the response may be results:

[{name: “xyz”, place: “abc”, date: “123”}]

but sometimes it may be:

[{name: “xyz”, place: “abc”}]

How do I handle this with IF (or anything else)?

I’m getting the “object reference not set to an instance of an object” error. I have tried using the deserialize portion inside an IF block which checks wherther isNothing(object), but same error.

Current implementation pic attached.

Any help appreciated!

Maybe, the year variable has not been declared in the data manager palette

Hi,
I think it’s the ToString method that is throwing the error. Since we are doing a ToString on an object that doesn’t exist
Can you try removing the ToString, and then try?

Thanks,
Nishant

1 Like

a null check can be done as shown below:
grafik

for a more defensive handling the existence of a JSON Property we can do:
grafik

we use this often for techniques when setting up generic extraction flows and and calculate existing properties against a list of interested properties

2 Likes

Brilliant, simple. Works now!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.