0

Create a custom storage credential

by
Published Apr 8, 2025

Creates a custom storage credentials configuration.

Script telnyx Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Telnyx = {
3
	apiKey: string
4
}
5
/**
6
 * Create a custom storage credential
7
 * Creates a custom storage credentials configuration.
8
 */
9
export async function main(
10
	auth: Telnyx,
11
	connection_id: string,
12
	body: {
13
		backend: 'gcs' | 's3' | 'azure'
14
		configuration:
15
			| { credentials?: string; bucket?: string }
16
			| {
17
					bucket?: string
18
					region?: {
19
						code: string
20
						name: string
21
						inserted_at?: string
22
						updated_at?: string
23
					}
24
					aws_access_key_id?: string
25
					aws_secret_access_key?: string
26
			  }
27
			| { bucket?: string; account_name?: string; account_key?: string }
28
	}
29
) {
30
	const url = new URL(`https://api.telnyx.com/v2/custom_storage_credentials/${connection_id}`)
31

32
	const response = await fetch(url, {
33
		method: 'POST',
34
		headers: {
35
			'Content-Type': 'application/json',
36
			Authorization: 'Bearer ' + auth.apiKey
37
		},
38
		body: JSON.stringify(body)
39
	})
40
	if (!response.ok) {
41
		const text = await response.text()
42
		throw new Error(`${response.status} ${text}`)
43
	}
44
	return await response.json()
45
}
46