0

Create a number block order

by
Published Apr 8, 2025

Creates a phone number block order.

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 block order
7
 * Creates a phone number block order.
8
 */
9
export async function main(
10
	auth: Telnyx,
11
	body: {
12
		id?: string
13
		record_type?: string
14
		starting_number: string
15
		range: number
16
		phone_numbers_count?: number
17
		connection_id?: string
18
		messaging_profile_id?: string
19
		status?: 'pending' | 'success' | 'failure'
20
		customer_reference?: string
21
		created_at?: string
22
		updated_at?: string
23
		requirements_met?: false | true
24
		errors?: string
25
	}
26
) {
27
	const url = new URL(`https://api.telnyx.com/v2/number_block_orders`)
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