0

Create a Global IP assignment

by
Published Apr 8, 2025

Create a Global IP assignment.

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 Global IP assignment
7
 * Create a Global IP assignment.
8
 */
9
export async function main(
10
	auth: Telnyx,
11
	body: {
12
		id?: string
13
		record_type?: string
14
		created_at?: string
15
		updated_at?: string
16
	} & {
17
		record_type?: string
18
		global_ip_id?: string
19
		wireguard_peer_id?: string
20
		status?: 'created' | 'provisioning' | 'provisioned' | 'deleting'
21
		is_connected?: false | true
22
		is_in_maintenance?: false | true
23
		is_announced?: false | true
24
	}
25
) {
26
	const url = new URL(`https://api.telnyx.com/v2/global_ip_assignments`)
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