0

Create a number reservation

by
Published Apr 8, 2025

Creates a Phone Number Reservation for multiple numbers.

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 number reservation
7
 * Creates a Phone Number Reservation for multiple numbers.
8
 */
9
export async function main(
10
	auth: Telnyx,
11
	body: {
12
		id?: string
13
		record_type?: string
14
		phone_numbers?: {
15
			id?: string
16
			record_type?: string
17
			phone_number?: string
18
			status?: 'pending' | 'success' | 'failure'
19
			created_at?: string
20
			updated_at?: string
21
			expired_at?: string
22
		}[]
23
		status?: 'pending' | 'success' | 'failure'
24
		customer_reference?: string
25
		created_at?: string
26
		updated_at?: string
27
	}
28
) {
29
	const url = new URL(`https://api.telnyx.com/v2/number_reservations`)
30

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