Programmatically set environment variables in initialDeployHook

Hello Render,

I’m attempting to setup a Preview Environment that successfully interacts with my Stripe integration.

To do so I need to create webhook endpoints in Stripe that reflect the appropriate PR url (which I can do via API calls: Stripe API reference – Webhook Endpoints)

When created, the API response returns a signing secret that I must store / make available to my application, preferably through an environment variable.

Is there a way, in my initialDeployHook, to add such an environment variable and assign it values on the preview environment instance?

For context, the initialDeployHook is written in Bash.

I’m not seeing support for such an action in the api docs, thanks!

P.S. open to alternative solutions to get this working

Hi @mrjonesbot, welcome to the Render community!

Unfortunately, we don’t have a specific endpoint yet for programmatically setting environment variables through our API (I think this is what you are looking for to make this an easy task). I have not tested this myself, but a possible workaround I can think of would be to create those environment variables in your dashboard (that should make them available to your application during build/runtime). Then in your initialDeployHook script change their value based on what is returned by the Stripe API.