0

Update a Global IP assignment

by
Published Apr 8, 2025

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

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