TL;DR: API Connector is sending the wrong data to an API, using an old version of the parameter (or null on page load), probably due to a race condition - and it’s not clear how to fix that given the tools available…?
I’ve got a moderately complex app page where the user makes some suggestions, and as changes are made I then need to take their selections and convert them to JSON, which I then send to a third party API (from Prolific) to get back some feedback which I then update on the page.
The JSON is complex enough to build that I use a plugin custom element that takes a list of Things (which have been updated by the UI) and publishes out the JSON in a custom state. Logging shows me that the JSON generation is working fine given.
The API call is triggered by various things (on page load, on value change, on click) which all fire a Custom Event that then does a few setup steps (eg. kick off a waiting animation via a Custom State change that hides status / shows animation), then uses API Connector to call the API, takes the response and updates the UI.
When I redirect the API call to a server I control I can see that the API call seems to pretty consistently send the wrong data, using an old value - when I trigger this on page load then it sends null, if I trigger it when a UI element’s value changes it sends the version of JSON generated before the UI change happened, despite being initiated from a workflow several steps after the underlying DB Things have been updated. Adding 1-2 second pauses to the workflow before the API Connector step makes no difference, but using the debugger to pause on the preceding step will cause the right data to be sent.
Clearly Bubble is reading/writing Things asynchronously, with the workflow steps continuing before the Thing changes have returned and triggered the JSON update, and I’ve got a race condition. It’s not clear to me how I can solve that, given the tools Bubble makes available…?