I have an API with may calls used all over the app. We have set up authentication as OAuth2 password flow, with a separate URL and separate credentials for Dev and Prod environments it is connecting to, depending on whthere it is bubble’s dev or live environment. However, it seems bubble does not support variables in the Token endpoint. How do I set up the API so it gets the auth token from the correct environment (dev URL for dev and prod URL for live)?
When setting a new API call, you can pass URL parameters. Just us that feature to send the whole endpoint dynamically:
Hi,
The call has the dynamic URL for dev/prod set up already, the issue is at the API authentication level, where you set it up as OAuth2 password flow. The token URL does not seem to to take parameters like the calls do, so it looks like it is a fixed URL and ussername/password .shared by all calls, whether the calls themselves target a dev or prod URL.
Create two separate API setups in the API Connector plugin (one named “Dev” / one named “Prod”), each with its own Token URL + credentials. Then in your workflows choose which API to call based on environment.
Yeah, this is a common issue with Bubble, the Token endpoint doesn’t support dynamic variables, so you can’t just swap URLs automatically based on dev vs live. One workaround I use is to create two separate API connections in the API Connector: one for Dev and one for Prod, each with its own Token URL and credentials. Then in your workflows or calls, you choose the appropriate API connection depending on the environment.
It’s a bit repetitive, but it’s the most reliable way to make sure the token comes from the right environment. Another approach is to use a backend workflow to fetch the token dynamically and store it in a custom state or database field, but that’s a bit more advanced.
This setup has worked well for me when you need fully separate Dev and Prod auth.
Did you tried to use custom token instead?
This one let you use dynamic value. I don’t remember, but the JSON part could accept url parameters like regular API call can.
Another option is to use a manual auth instead of Bubble prebuilt password auth. Create a call to get the credentials and use the result of this call into other call after.
I don’t recommend @connect10 or @anneatkin063 solution to create two separate API Connection. This is a bad idea from my point of view that will make you app harder to maintain and maybe cost more WU…
I am not keen on having two distinct API connections. Coudl you tell me more about th eother alternative?
