Best answer

How to select an environment variable for staging or production URL API call

  • 12 August 2021
  • 1 reply
  • 1214 views

Userlevel 1

Hi, 

I would like to know how can I let users to choose the environment of their zaps

like to have an endpoint that makes API calls to a staging/sandbox environment URL and other for production. 

I don’t want to have different version pointing to different environments, just an option to select the variable URL, like a dropdown list  or something similar when choosing the zapier account. 

Best regards

 

Luis M.

icon

Best answer by Zane 13 August 2021, 16:24

View original

This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

1 reply

Userlevel 7
Badge +9

An approach that I think you could take here:

 

  1. Define environment variables for both staging and prod. staging_base_url, prod_base_url, staging_client_id, prod_client_id, etc
  2. Add an input field to your auth configuration in your Zapier integration. Maybe static dropdown with production and staging selections. Or a boolean for staging. Either way it should default to production. 
  3. Now, every place you reference a base url, or other environment variable, you’ll check bundle.inputData.environment (or whatever key you choose) and use a conditional to say if it’s staging use this env variable, if it’s prod use that environment variable. You could build some helper functions to make that easier. If you’re using the UI builder environment you’ll need to use ‘code mode’ pretty much everywhere - and it’s going to be easier to manage your code in the Zapier CLI if you have more than a couple triggers and actions. 

I don’t love this approach if you’re planning on publishing your integration on the Zapier App Directory. I’d like to find a way for regular users to not see that choice. But if you’re building for yourself or your team I think this approach is pretty good.