Forum Academy Marketplace Showcase Pricing Features

(solved) Prevent an API call from running until button is pressed

here’s a simple bubble app that i built that calls indeed.com’s job API. i’m using a “data” API call rather than an “action” API call. i like “data” rather than “action” API calls in this case.

(this is my first time sharing an app, so i’m assuming that other users can open it up and look at it behind the scenes. if not, please let me know.)

upon page load, job search results are loaded immediately based on the default values in the input fields. you’ll see them at the bottom of the screen once the page loads. i don’t want the app to do this. i want the app to wait to call the API until the user clicks the “get jobs” button, and not before.

it seems like i’m halfway there. the app DOES work this way AFTER the button is pressed for the first time, and every time thereafter (the app waits for the user to push the “get jobs” button before applying the new search parameters). but i want the page to work this way (wait to call the API until the “get jobs” button is pressed) upon page load. i don’t want any API data to load without the user expressly calling the data by pushing the button. again, it works this way already, but only after the “get jobs” button is pressed for the first time.

any suggestions on getting the page to work this way?

the reason i want the app to wait to call the API is because i’m planning to use a paid API that charges me per query. i don’t want to be charged for an API call that was called upon page load–the user doesn’t have any user for those default results. bubble also appears to run the call as you’re typing–so if you’re typing out “account manager” as the search term, bubble appears to run the call before i’m even done typing. this can get really wasteful and expensive on a paid API. so i really want to set up the app to wait until the “get jobs” button is pressed before any API data is called.

thanks for any help you can provide–these forums have already been really helpful!

Just remove the API call from your repeating group.

p.s. the editor link is …

1 Like

I had the same issue with my app and I solved it by setting a custom state to the input I use to do the query. I set a yes/no custom state to this input.
This state is “no” by default and when the user clicks the search button it changes to “yes”, and when the input changes because the user is typing again it changes to “no”.
By doing so, you can set a conditional state when getting data from the API, so it will only make the call whe the custom state of the input is “yes”, and the input’s value is not empty and the inpus is not focused.
Hope it helps! :wink:

1 Like

thanks to both @NigelG and @Diego for their solutions!

so much to learn . . .