0

List Ips

by
Published Apr 8, 2025

Get all IPs belonging to the user that match the given filters.

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 Ips
7
 * Get all IPs belonging to the user that match the given filters.
8
 */
9
export async function main(
10
	auth: Telnyx,
11
	page_number_: string | undefined,
12
	page_size_: string | undefined,
13
	filter_connection_id_: string | undefined,
14
	filter_ip_address_: string | undefined,
15
	filter_port_: string | undefined
16
) {
17
	const url = new URL(`https://api.telnyx.com/v2/ips`)
18
	for (const [k, v] of [
19
		['page[number]', page_number_],
20
		['page[size]', page_size_],
21
		['filter[connection_id]', filter_connection_id_],
22
		['filter[ip_address]', filter_ip_address_],
23
		['filter[port]', filter_port_]
24
	]) {
25
		if (v !== undefined && v !== '' && k !== undefined) {
26
			url.searchParams.append(k, v)
27
		}
28
	}
29
	const response = await fetch(url, {
30
		method: 'GET',
31
		headers: {
32
			Authorization: 'Bearer ' + auth.apiKey
33
		},
34
		body: undefined
35
	})
36
	if (!response.ok) {
37
		const text = await response.text()
38
		throw new Error(`${response.status} ${text}`)
39
	}
40
	return await response.json()
41
}
42