How to handle development/staging APIs with Bubble?

Our Bubble front end interacts with our own backend APIs. We would like our development version of Bubble to hit a different API domain than our public version. Is there a way to do this dynamically instead of having to re-write every single API connector call?

First up, youā€™ll want to build these API calls into a private plugin. If you have already built them out in the API Connector, you can copy and paste them across by right clicking on the entire call.

You can then create variables in the API URLs by using square brackets, for example;

https://[hostname]/my-interesting-endpoint

You then specify this variable as Secret and it appears in the plugin tab for you to specify a value for Development version vs Live version.

2 Likes

Awesome, that worked - thanks a lot!

1 Like

Hey @juicebox ,

Thanks for this! Iā€™ve just tested your suggestion and it works perfectly from a plugin point of view. Just to double check though, does this mean that all existing data and action API calls on the app pages (and backend) now need to be updated to use the Private Plugin as opposed to the API Connector directly?

I think I already know the answer butā€¦ Iā€™ve spent months settings up API calls and testing them in my Test environment, etc with the assumption that the API connector would present a way of managing the production URLā€™s and keys once deployed to Live as this must be a fairly common requirement and in all the documentation Iā€™ve read, Iā€™ve not seen anything which suggests this method (of creating a private plugin) be done up front.

Any advice would be welcome here

Thanks!

Correct.

I donā€™t think I ever saw any documentation about encouraging the use of private plugins instead of the API connector - I agree it would make sense for Bubble to flag this with customers, perhaps within the API Connector interface.

I suspect that Bubble likes having a simplified version as the API connector as itā€™s a easier learning curve than developing your own plugin (but not by much!).

2 Likes

Thanks for the quick response @juicebox!

Looks like Iā€™m going to have a busy few days migrating this stuff. If you think of anything else RE this topic, please let me know!

Have a great weekend! :blush:

Thanks for the solution! Working nicely!

One question I came up with:

  • for every call we will need to specify the desired url for Dev and Live environments, right? If you have 10 Api calls, we would have 10 dev hosts and 10 live hosts, even though all 10 are the same.
    As setting up ā€˜hostā€™ as a shared parameter doesnā€™t seem to work

Correct.

Shared parameters definitely arenā€™t as flexible as weā€™d like them to be!

that sucks :frowning_face:

Well, it sucks maybe a bit, if you set up your API calls like this you dont need to create seperate calls for Live and Dev:

In the action use a condition to determine the URL:

For the Header you can do pretty much the same, additionally save it encrypted and external for extra security.

5 Likes

What about for OAuth2 where the ā€œToken endpoint (POST)'ā€ URL also should be dynamic between live and dev? - I canā€™t find a way to make this dynamic and show up in the plugin tab.