0

List FQDNs

by
Published Apr 8, 2025

Get all FQDNs 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 FQDNs
7
 * Get all FQDNs 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_fqdn_: string | undefined,
15
	filter_port_: string | undefined,
16
	filter_dns_record_type_: string | undefined
17
) {
18
	const url = new URL(`https://api.telnyx.com/v2/fqdns`)
19
	for (const [k, v] of [
20
		['page[number]', page_number_],
21
		['page[size]', page_size_],
22
		['filter[connection_id]', filter_connection_id_],
23
		['filter[fqdn]', filter_fqdn_],
24
		['filter[port]', filter_port_],
25
		['filter[dns_record_type]', filter_dns_record_type_]
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