0

List FQDN connections

by
Published Apr 8, 2025

Returns a list of your FQDN connections.

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 FQDN connections
7
 * Returns a list of your FQDN connections.
8
 */
9
export async function main(
10
	auth: Telnyx,
11
	page_number_: string | undefined,
12
	page_size_: string | undefined,
13
	filter_connection_name__contains_: string | undefined,
14
	filter_fqdn_: string | undefined,
15
	filter_outbound_voice_profile_id_: string | undefined,
16
	sort: 'created_at' | 'connection_name' | 'active' | undefined
17
) {
18
	const url = new URL(`https://api.telnyx.com/v2/fqdn_connections`)
19
	for (const [k, v] of [
20
		['page[number]', page_number_],
21
		['page[size]', page_size_],
22
		['filter[connection_name][contains]', filter_connection_name__contains_],
23
		['filter[fqdn]', filter_fqdn_],
24
		['filter[outbound_voice_profile_id]', filter_outbound_voice_profile_id_],
25
		['sort', sort]
26
	]) {
27
		if (v !== undefined && v !== '' && k !== undefined) {
28
			url.searchParams.append(k, v)
29
		}
30
	}
31
	const response = await fetch(url, {
32
		method: 'GET',
33
		headers: {
34
			Authorization: 'Bearer ' + auth.apiKey
35
		},
36
		body: undefined
37
	})
38
	if (!response.ok) {
39
		const text = await response.text()
40
		throw new Error(`${response.status} ${text}`)
41
	}
42
	return await response.json()
43
}
44