0

Add or update environment variable

by
Published Oct 17, 2025

Add or update a particular environment variable in a particular environment group.

Script render Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Render = {
3
	apiKey: string
4
}
5
/**
6
 * Add or update environment variable
7
 * Add or update a particular environment variable in a particular environment group.
8

9
 */
10
export async function main(
11
	auth: Render,
12
	envGroupId: string,
13
	envVarKey: string,
14
	body: { value: string } | { generateValue: false | true }
15
) {
16
	const url = new URL(`https://api.render.com/v1/env-groups/${envGroupId}/env-vars/${envVarKey}`)
17

18
	const response = await fetch(url, {
19
		method: 'PUT',
20
		headers: {
21
			'Content-Type': 'application/json',
22
			Authorization: 'Bearer ' + auth.apiKey
23
		},
24
		body: JSON.stringify(body)
25
	})
26
	if (!response.ok) {
27
		const text = await response.text()
28
		throw new Error(`${response.status} ${text}`)
29
	}
30
	return await response.json()
31
}
32