Check for 0 results returned from API call

When using API Explorer to return an array of items, is there a way to tell if nothing is returned and generate an event based on that? It just seems like there would be a way to check for 0 results returned. I put in a request for a feature like this a couple years back, but I’m just curious if anybody has found a way to make this happen without having to modify the API to add a count.

Hey Chuck @programmers,

That is really dependent on the API itself.
One common way is to use the “Request Completed” trigger, then use a conditional trigger to test one of the properties of the items returned. If it’s empty, then you got 0 results.
Another way, depending on the API again, is to look for a new “message”/“status”/… field in the response returned by the API when there are no answers. You might need to manually edit the IFD to both look for “regular response fields” and this additional one.

1 Like

Got ya. That makes since.

Hi @programmers , I do this all the time. Typically just to show a message that zero results were found. Just bind the visibility of a text item to the “number of records” (if your api returns that). Use the ‘is equal to’ binding converter and set it to zero. That way, whenever there are zero results, the text item shows, when there is anything else, the text item is hidden.

You can make it more complex than this, however. You could trigger almost any action, either by binding a toggle button’s checked status, or binding any other property.

If your api doesn’t return number of records, perhaps you can use a set-trigger. When call is completed, set a text item or global variable to a field in your data. If zero records are returned, the tex item or global variable will be blank. Then bind a toggle to that text item and use the custom converter:
if (INPUT.length < 1)
Or like the first example, you could bind any property to it. The trigger only happens when the number of characters in the text item is less than one…which is zero. Mihai gave me this tipe, and the less than zero tends to work better in my opinion than equals zero.

Hope that sparks some ideas. Or feel free to share screenshots of your api call and maybe there’s other ways.


Thanks for the Great ideas!

In my particular situation, I’m going to have to request a single record returned with a special type parameter when nothing is available to return in the result set.