with the api workflow you can set the actual workflow to return data to the thing that called it (rather than the standard 200 response). If you’re doing everything in bubble then you likely don’t need to return data from the API that you’ve called.
how you have it setup sounds correct.
I’d normally send the list of things to process and then minus the items from the list each time and do the count separately (I don’t count the items left incase they don’t minus off for some reason). Counting up is the most fail-safe method so I use that.
What’s important to note about custom events is that they all wait for the entire of the custom event to fully process before the “event” is completed and the next actions process in the workflow.
So if you have custom events nested within each other then level 1 will wait for level 2, level 2 waits for level 3, level 3 waits for 4… therefore level one waits for 1,2,3,4 (all the nested custom events).
The return data from API step that you have as the last step gets evaluated each api run (each loop). So you need to make sure that if you’re returning data there that you are holding that data through all the loops so you can return it in the final step.
ie if you’re creating temp calc and need to return 10 of the created temp calcs then you need to have a list of them on the loop and add to the list each loop, then reference that list in the api return step.
you’ll also need to be mindful of how all the custom events and other data triggers/api workflows interact with the data during this process - I’ve often had unexpected issues because I’ve had data triggered workflows that are triggered during a loop that then affect the final output unexpectedly.
normally what I do to debug this is create a record for all the steps so I can precisely see the inputs/outputs in a simple text format (no need to try and sift through the bubble logs). then I can narrow down what is working and what isn’t, check for looping issues and timing issues (since the debug records are created directly after each step that runs I know when each step ran and can see if it is in the order I intended)
for instance in your screenshot - if you held the list of temp calcs on the api workflow step and that step has a condition to not run on the last step then the list would be empty for the return data to api (if you referenced it from the api step that didn’t run).
to get around that I’d nest the api step in a custom event and have the custom event return the list and just condition the api call within it. the two steps that run on the last recursion should also be in a custom event - 1 you only evaluate the condition once (less WU units) and 2 they then evaluate in sequence rather than potentially at the same time. The api workflow step of create and repeat I’d also put in a custom event.
essentially the api workflow “calculate tiers 1” would have 2 custom events in it. the complete event needs to be BEFORE the loop event (so the condition is evaluated before the loop changes it again).
in general most bubblers need to use far more custom events than they do.