0

Create a WireGuard Interface

by
Published Apr 8, 2025

Create a new WireGuard Interface. Current limitation of 10 interfaces per user can be created.

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 WireGuard Interface
7
 * Create a new WireGuard Interface. Current limitation of 10 interfaces per user can be created.
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
		network_id?: string
18
		name?: string
19
		status?: 'created' | 'provisioning' | 'provisioned' | 'deleting'
20
	} & {
21
		record_type?: string
22
		endpoint?: string
23
		public_key?: string
24
		enable_sip_trunking?: false | true
25
	} & { region_code?: string } & {}
26
) {
27
	const url = new URL(`https://api.telnyx.com/v2/wireguard_interfaces`)
28

29
	const response = await fetch(url, {
30
		method: 'POST',
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