0

List environments

by
Published Oct 17, 2025

List a particular project's environments matching the provided filters. If no filters are provided, all environments are returned.

Script render Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Render = {
3
	apiKey: string
4
}
5
/**
6
 * List environments
7
 * List a particular project's environments matching the provided filters. If no filters are provided, all environments are returned.
8

9
 */
10
export async function main(
11
	auth: Render,
12
	name: string | undefined,
13
	projectId: string | undefined,
14
	createdBefore: string | undefined,
15
	createdAfter: string | undefined,
16
	updatedBefore: string | undefined,
17
	updatedAfter: string | undefined,
18
	ownerId: string | undefined,
19
	environmentId: string | undefined,
20
	cursor: string | undefined,
21
	limit: string | undefined
22
) {
23
	const url = new URL(`https://api.render.com/v1/environments`)
24
	for (const [k, v] of [
25
		['name', name],
26
		['projectId', projectId],
27
		['createdBefore', createdBefore],
28
		['createdAfter', createdAfter],
29
		['updatedBefore', updatedBefore],
30
		['updatedAfter', updatedAfter],
31
		['ownerId', ownerId],
32
		['environmentId', environmentId],
33
		['cursor', cursor],
34
		['limit', limit]
35
	]) {
36
		if (v !== undefined && v !== '' && k !== undefined) {
37
			url.searchParams.append(k, v)
38
		}
39
	}
40
	const response = await fetch(url, {
41
		method: 'GET',
42
		headers: {
43
			Authorization: 'Bearer ' + auth.apiKey
44
		},
45
		body: undefined
46
	})
47
	if (!response.ok) {
48
		const text = await response.text()
49
		throw new Error(`${response.status} ${text}`)
50
	}
51
	return await response.json()
52
}
53