0

Import variables

by
Published Oct 17, 2025

Import environment variables in a defined scope, with a defined visibility.

Script qovery Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
/**
3
 * Import variables
4
 * Import environment variables in a defined scope, with a defined visibility.
5
 */
6
export async function main(
7
	auth: RT.Qovery,
8
	service_id: string | undefined,
9
	service_type: 'APPLICATION' | 'CONTAINER' | 'JOB' | 'HELM' | 'TERRAFORM' | undefined,
10
	body: Body
11
) {
12
	const url = new URL(`https://api.qovery.com/variable/import`)
13
	for (const [k, v] of [
14
		['service_id', service_id],
15
		['service_type', service_type]
16
	]) {
17
		if (v !== undefined && v !== '') {
18
			url.searchParams.append(k, v)
19
		}
20
	}
21
	const response = await fetch(url, {
22
		method: 'POST',
23
		headers: {
24
			'Content-Type': 'application/json',
25
			Authorization: 'Token ' + auth.apiKey
26
		},
27
		body: JSON.stringify(body)
28
	})
29
	if (!response.ok) {
30
		const text = await response.text()
31
		throw new Error(`${response.status} ${text}`)
32
	}
33
	return await response.json()
34
}
35

36
/* eslint-disable */
37
/**
38
 * This file was automatically generated by json-schema-to-typescript.
39
 * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
40
 * and run json-schema-to-typescript to regenerate this file.
41
 */
42

43
export interface Body {
44
	overwrite: boolean
45
	vars: {
46
		name: string
47
		value: string
48
		scope:
49
			| 'APPLICATION'
50
			| 'BUILT_IN'
51
			| 'ENVIRONMENT'
52
			| 'PROJECT'
53
			| 'CONTAINER'
54
			| 'JOB'
55
			| 'HELM'
56
			| 'TERRAFORM'
57
		is_secret: boolean
58
		[k: string]: unknown
59
	}[]
60
	[k: string]: unknown
61
}
62