0

List notification settings

by
Published Apr 8, 2025

List notification settings.

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 notification settings
7
 * List notification settings.
8
 */
9
export async function main(
10
	auth: Telnyx,
11
	page_number_: string | undefined,
12
	page_size_: string | undefined,
13
	filter_notification_profile_id__eq_: string | undefined,
14
	filter_notification_channel__eq_: string | undefined,
15
	filter_notification_event_condition_id__eq_: string | undefined,
16
	filter_associated_record_type__eq_: 'account' | 'phone_number' | undefined,
17
	Status: 'canceled' | 'completed' | 'failed' | 'busy' | 'no-answer' | undefined
18
) {
19
	const url = new URL(`https://api.telnyx.com/v2/notification_settings`)
20
	for (const [k, v] of [
21
		['page[number]', page_number_],
22
		['page[size]', page_size_],
23
		['filter[notification_profile_id][eq]', filter_notification_profile_id__eq_],
24
		['filter[notification_channel][eq]', filter_notification_channel__eq_],
25
		['filter[notification_event_condition_id][eq]', filter_notification_event_condition_id__eq_],
26
		['filter[associated_record_type][eq]', filter_associated_record_type__eq_],
27
		['Status', Status]
28
	]) {
29
		if (v !== undefined && v !== '' && k !== undefined) {
30
			url.searchParams.append(k, v)
31
		}
32
	}
33
	const response = await fetch(url, {
34
		method: 'GET',
35
		headers: {
36
			Authorization: 'Bearer ' + auth.apiKey
37
		},
38
		body: undefined
39
	})
40
	if (!response.ok) {
41
		const text = await response.text()
42
		throw new Error(`${response.status} ${text}`)
43
	}
44
	return await response.json()
45
}
46