0

List all Interfaces for a Network.

by
Published Apr 8, 2025

List all Interfaces for a Network.

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 Interfaces for a Network.
7
 * List all Interfaces for a Network.
8
 */
9
export async function main(
10
	auth: Telnyx,
11
	id: string,
12
	page_number_: string | undefined,
13
	page_size_: string | undefined,
14
	filter_name_: string | undefined,
15
	filter_type_: string | undefined,
16
	filter_status_: 'created' | 'provisioning' | 'provisioned' | 'deleting' | undefined
17
) {
18
	const url = new URL(`https://api.telnyx.com/v2/networks/${id}/network_interfaces`)
19
	for (const [k, v] of [
20
		['page[number]', page_number_],
21
		['page[size]', page_size_],
22
		['filter[name]', filter_name_],
23
		['filter[type]', filter_type_],
24
		['filter[status]', filter_status_]
25
	]) {
26
		if (v !== undefined && v !== '' && k !== undefined) {
27
			url.searchParams.append(k, v)
28
		}
29
	}
30
	const response = await fetch(url, {
31
		method: 'GET',
32
		headers: {
33
			Authorization: 'Bearer ' + auth.apiKey
34
		},
35
		body: undefined
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