0

Create a WireGuard Peer

by
Published Apr 8, 2025

Create a new WireGuard Peer. Current limitation of 5 peers per interface 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 Peer
7
 * Create a new WireGuard Peer. Current limitation of 5 peers per interface can be created.
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
	} & { public_key?: string } & {
18
		record_type?: string
19
		last_seen?: string
20
		wireguard_interface_id?: string
21
		private_key?: string
22
	} & {}
23
) {
24
	const url = new URL(`https://api.telnyx.com/v2/wireguard_peers`)
25

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