0

Create a Migration

by
Published Apr 8, 2025

Initiate a migration of data from an external provider into Telnyx Cloud Storage. Currently, only S3 is supported.

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 Migration
7
 * Initiate a migration of data from an external provider into Telnyx Cloud Storage. Currently, only S3 is supported.
8
 */
9
export async function main(
10
	auth: Telnyx,
11
	body: {
12
		id?: string
13
		source_id: string
14
		target_bucket_name: string
15
		target_region: string
16
		refresh?: false | true
17
		last_copy?: string
18
		status?: 'pending' | 'checking' | 'migrating' | 'complete' | 'error' | 'stopped'
19
		bytes_to_migrate?: number
20
		bytes_migrated?: number
21
		speed?: number
22
		eta?: string
23
		created_at?: string
24
	}
25
) {
26
	const url = new URL(`https://api.telnyx.com/v2/storage/migrations`)
27

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