TLDR:
- calling backend workflow from API connector is unreasonably tedious
- app connector auto-sets up and syncs fields
- result/returned data from backend workflow can be used in following front-end steps
Returning data from backend workflow in front-end without manually setting up API connector calls
I have a lot of feelings today, as I’ve learned something that would’ve saved me hours of time had I known earlier, and it feels like something that only a handful of people know about (based on the comments on the custom event return data announcement)
If you want to call a backend workflow in the front-end and use the return data from API action to get data from the backend workflow into the front-end, people generally use the API connector. That might look something like this:
You can then make an API call to your own app. This has a few problems:
- time consuming to set up and initialise
- generally requires you to manually add relevant data into the workflow to ensure it runs without an error
- if you want to change a parameter even slightly in the BE workflow, you have to do the same in the API call
Bubble App Connector
This is a fairly quiet feature/plugin from Bubble. It was designed to connect two different apps together with data / workflows. However, you can actually use it to connect your app too… itself.
With this method:
- you can trigger backend workflows to run synchronously from the front-end
- as a consequence, you can use the returned data in following front-end steps
- any backend workflow changes are easily updated in the API calls
Here I have an arbitrary backend workflow that I want to call from the front-end:
It takes a text field, a User, and a dateOfBirth. It then returns data - for this example made it always return ‘30’ but it could return as many things as you’d like:
Now, let’s install the App Connector plugin and set it up. It’s straight forward and you’ll only need to do it once.
Then, ‘Refresh app metadata’ and add the relevant backend workflow:
Let’s go to the page where we want to call this backend workflow.
We use the ‘Run (appname) (workflowname)’ action.
This will give us the fields to fill. It will also verify that we’re providing the right field type (if I put a text in the dateOfBirth field, it’ll stay red as it requires a date).
Then, we can use the result of this API call in the next step:
And that’s it. It behaves exactly like an API call from the API connector. If you change the backend workflow’s required input or the data it returns, just ‘refresh app metadata’ in the app connector plugin area. One note is that ‘refresh app metadata’ doesn’t appear to work on branches other than the main development branch, so if you don’t see a new workflow there or it’s not updating as expected try refreshing on main.
I just can’t believe I only learned about it today and it’s been kept so quiet in general!