0

List all Access IP Ranges

by
Published Apr 8, 2025
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 Access IP Ranges
7
 *
8
 */
9
export async function main(
10
	auth: Telnyx,
11
	filter_cidr_block_: string | undefined,
12
	filter_cidr_block__startswith_: string | undefined,
13
	filter_cidr_block__endswith_: string | undefined,
14
	filter_cidr_block__contains_: string | undefined,
15
	filter_created_at__gt_: string | undefined,
16
	filter_created_at__lt_: string | undefined,
17
	page_number_: string | undefined,
18
	page_size_: string | undefined
19
) {
20
	const url = new URL(`https://api.telnyx.com/v2/access_ip_ranges`)
21
	for (const [k, v] of [
22
		['filter[cidr_block]', filter_cidr_block_],
23
		['filter[cidr_block][startswith]', filter_cidr_block__startswith_],
24
		['filter[cidr_block][endswith]', filter_cidr_block__endswith_],
25
		['filter[cidr_block][contains]', filter_cidr_block__contains_],
26
		['filter[created_at][gt]', filter_created_at__gt_],
27
		['filter[created_at][lt]', filter_created_at__lt_],
28
		['page[number]', page_number_],
29
		['page[size]', page_size_]
30
	]) {
31
		if (v !== undefined && v !== '' && k !== undefined) {
32
			url.searchParams.append(k, v)
33
		}
34
	}
35
	const response = await fetch(url, {
36
		method: 'GET',
37
		headers: {
38
			Authorization: 'Bearer ' + auth.apiKey
39
		},
40
		body: undefined
41
	})
42
	if (!response.ok) {
43
		const text = await response.text()
44
		throw new Error(`${response.status} ${text}`)
45
	}
46
	return await response.json()
47
}
48