0

List all phone number configurations

by
Published Apr 8, 2025

Returns a list of phone number configurations paginated.

Script telnyx Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Telnyx = {
3
	apiKey: string
4
}
5
/**
6
 * List all phone number configurations
7
 * Returns a list of phone number configurations paginated.
8
 */
9
export async function main(
10
	auth: Telnyx,
11
	page_number_: string | undefined,
12
	page_size_: string | undefined,
13
	filter_porting_order_id_: string | undefined,
14
	filter_porting_order_id__in___: string | undefined,
15
	filter_porting_order_status_:
16
		| 'activation-in-progress'
17
		| 'cancel-pending'
18
		| 'cancelled'
19
		| 'draft'
20
		| 'exception'
21
		| 'foc-date-confirmed'
22
		| 'in-process'
23
		| 'ported'
24
		| 'submitted'
25
		| undefined,
26
	filter_porting_order_status__in___: string | undefined,
27
	filter_porting_phone_number_: string | undefined,
28
	filter_porting_phone_number__in___: string | undefined,
29
	filter_user_bundle_id_: string | undefined,
30
	filter_user_bundle_id__in___: string | undefined,
31
	sort__: 'created_at' | '-created_at' | undefined
32
) {
33
	const url = new URL(`https://api.telnyx.com/v2/porting_orders/phone_number_configurations`)
34
	for (const [k, v] of [
35
		['page[number]', page_number_],
36
		['page[size]', page_size_],
37
		['filter[porting_order_id]', filter_porting_order_id_],
38
		['filter[porting_order_id][in][]', filter_porting_order_id__in___],
39
		['filter[porting_order.status]', filter_porting_order_status_],
40
		['filter[porting_order.status][in][]', filter_porting_order_status__in___],
41
		['filter[porting_phone_number]', filter_porting_phone_number_],
42
		['filter[porting_phone_number][in][]', filter_porting_phone_number__in___],
43
		['filter[user_bundle_id]', filter_user_bundle_id_],
44
		['filter[user_bundle_id][in][]', filter_user_bundle_id__in___],
45
		['sort[]', sort__]
46
	]) {
47
		if (v !== undefined && v !== '' && k !== undefined) {
48
			url.searchParams.append(k, v)
49
		}
50
	}
51
	const response = await fetch(url, {
52
		method: 'GET',
53
		headers: {
54
			Authorization: 'Bearer ' + auth.apiKey
55
		},
56
		body: undefined
57
	})
58
	if (!response.ok) {
59
		const text = await response.text()
60
		throw new Error(`${response.status} ${text}`)
61
	}
62
	return await response.json()
63
}
64