Calling an API & running it against a data table using the Recursive Behavior

Hey,

I am running into a problem where I am calling an API end point but I need to call it each time for a specific line item in my database, the line item count varies so I have no way to say stop running after the nth time.

Does anyone have an idea how I could establish how many line items in my DB that fit that criteria & from there then run the API look up that any times?

Search for the items that match your criteria, count the list, then schedule an api workflow that calls the endpoint you need for each item. This API workflow will have a parameter for the total count, a parameter for the iteration (number), and of course a parameter for the list of things your iterating through. This workflow will also have a condition to only run when the current iteration’s number is less than or equal to the total count parameter. Add the action to call the api and use the list’s:item number: iteration to identify the specific record. The last action of the workflow will be a schedule api action so that the workflow schedules itself to run. Pass the same list of items, and same count number, and simply increase the iteration by 1.

Hey Alex,

Thanks so much for this, I am looking to complete it this exact way mentioned, not sure if I am simply overlooking it, but I cannot find a way to do a “search for items that match my criteria”

Yeah it’s a bit tricky at first if you’re just learning Bubble. When you want to fetch a list you can use the action “make changes to a list of things”. You can construct your search and specify constraints in that action. Then when you want to schedule the api workflow, the expression for the list paramter can be Result of Step 1’s list of …

Looks like I can get the count which is great, thanks again!

However, I am still stuck where it only runs the first items looks up key in the API & not the other two (the case I am using at the moment has 3 lists to run through)

Can you post screens of your workflow and actions?

No problem, during this process, I have realised I probably want to run this as a list as from the API I get the data back & I want to split each of the relevant chunks into their own rows in my DB.

BACKEND WORKFLOWS:

So right now I set the data I want

From there I create a the users data with the mergefields of what will go into my db


PAGE WORKFLOWS

On page load, I then want the backend workflow to trigger & add everything

Note at this point everything is working perfectly, however, the problem now comes in over at this point, I have to look up on another DB of mine for id_tokens to run through the system, the DB I am looking up may have 1 id_token or it could have 999 id_tokens - currently as it runs, it only runs on the first one in the lookup I have set, I know I made it go to the first item (that was to conceptually see everything is running) however, here is where I would like it to loop for each id_token to populate the original DB - so you can see I am calling an API to populate DB one (user post) but I need to leverage the stored id_tokens from DB two (ad posts) which could contain multiple id_tokens

Can you construct it differently so that you’re able to fetch the full list of tweet data? Or do you you need to make one api call per ad account? If it’s the latter, then move that call to the backend in a recursive workflow