0

List variables

by
Published Oct 17, 2025

Returns a list of variables. The result can be filtered by using the query parameters.

Script qovery Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
/**
3
 * List variables
4
 * Returns a list of variables. The result can be filtered by using the query parameters.
5
 */
6
export async function main(
7
	auth: RT.Qovery,
8
	parent_id: string | undefined,
9
	scope:
10
		| 'APPLICATION'
11
		| 'BUILT_IN'
12
		| 'ENVIRONMENT'
13
		| 'PROJECT'
14
		| 'CONTAINER'
15
		| 'JOB'
16
		| 'HELM'
17
		| 'TERRAFORM'
18
		| undefined,
19
	is_secret?: string | undefined
20
) {
21
	const url = new URL(`https://api.qovery.com/variable`)
22
	for (const [k, v] of [
23
		['parent_id', parent_id],
24
		['scope', scope],
25
		['is_secret', is_secret]
26
	]) {
27
		if (v !== undefined && v !== '') {
28
			url.searchParams.append(k, v)
29
		}
30
	}
31
	const response = await fetch(url, {
32
		method: 'GET',
33
		headers: {
34
			Authorization: 'Token ' + auth.apiKey
35
		},
36
		body: undefined
37
	})
38
	if (!response.ok) {
39
		const text = await response.text()
40
		throw new Error(`${response.status} ${text}`)
41
	}
42
	return await response.json()
43
}
44