How to trigger an event conditioned on an API fetch completing?

I’m using the API provider to fetch some json data from a remote server, and would like to hide an element until the response comes back. Is there a way to do this based on a successful HTTP response? The closest thing I can imagine is using a condition on the group’s fetch response’s results having a :count >= 0, or maybe it’s raw body text is not empty, but that’s not quite the same as looking for a successful HTTP response.

Furthermore, the user can change the query based on a date widget, so I’d like to clear the old value and display nothing until the new data comes back. However, something like a Workflow on the input value changing => {hiding a Text element and then showing it again based on one of the above} doesn’t appear to work. It’s as if the input state change workflow fires far later than the API fetch. Ah, in fact that appears to be the case. If the API request is delayed (e.g. suspend the backend server for a bit), it never triggers. Why is that?

Yes, that is possible. For example, step 2 is the api call, then add an action “Show an element” with a condition (Only when) “Result of step 2 [api call name] returned_an_error is No”.


Ah yes, that would work if I made the request as part of the Workflow. Right now I’m making the data fetch from an element as defined in its Data source field. When I reference that element’s API’s name, the only options I get to work with are the fields in the result, 's results, and 's raw body text. Would be nice if Bubble were more consistent in the conditions accessible… :confused:

True that. Probably not exactly what you are looking for, but in case you are displaying the data from that API in a repeating group, maybe you can use the ‘is loading’ state of the repeating group.


Interesting suggestion, but I can’t seem to get it to matter, even if I move the data fetch directly into the RG and the API request is delayed. I’m going to give up for now, although hopefully one day they expose consistent events for remote data fetches…thanks though.

1 Like

From what I understand, you’re unable to add the conditions mentioned above because you’re setting the data directly as the data source of your RG.

As an alternative, could you look at loading the data of your repeating group through a page load event trigger, or even a ‘do when condition is true’ workflow trigger.

This would allow you to add the condition on the workflow, then within the workflow, you could set the data source of the repeating group.

If a user then goes on to select a different value from the date picker, you could create another workflow to reset the data source of the RG again.

Not 100% sure if this is what you’re looking for, but it’s just an idea.