0

List network coverage locations

by
Published Apr 8, 2025

List all locations and the interfaces that region supports

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 network coverage locations
7
 * List all locations and the interfaces that region supports
8
 */
9
export async function main(
10
	auth: Telnyx,
11
	page_number_: string | undefined,
12
	page_size_: string | undefined,
13
	filters_available_services__contains_:
14
		| 'cloud_vpn'
15
		| 'private_wireless_gateway'
16
		| 'virtual_cross_connect'
17
		| undefined,
18
	filter_location_region_: string | undefined,
19
	filter_location_site_: string | undefined,
20
	filter_location_pop_: string | undefined,
21
	filter_location_code_: string | undefined
22
) {
23
	const url = new URL(`https://api.telnyx.com/v2/network_coverage`)
24
	for (const [k, v] of [
25
		['page[number]', page_number_],
26
		['page[size]', page_size_],
27
		['filters[available_services][contains]', filters_available_services__contains_],
28
		['filter[location.region]', filter_location_region_],
29
		['filter[location.site]', filter_location_site_],
30
		['filter[location.pop]', filter_location_pop_],
31
		['filter[location.code]', filter_location_code_]
32
	]) {
33
		if (v !== undefined && v !== '' && k !== undefined) {
34
			url.searchParams.append(k, v)
35
		}
36
	}
37
	const response = await fetch(url, {
38
		method: 'GET',
39
		headers: {
40
			Authorization: 'Bearer ' + auth.apiKey
41
		},
42
		body: undefined
43
	})
44
	if (!response.ok) {
45
		const text = await response.text()
46
		throw new Error(`${response.status} ${text}`)
47
	}
48
	return await response.json()
49
}
50