0

List all log messages

by
Published Apr 8, 2025

Retrieve a list of log messages for all external connections associated with your account.

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 log messages
7
 * Retrieve a list of log messages for all external connections associated with your account.
8
 */
9
export async function main(
10
	auth: Telnyx,
11
	page_number_: string | undefined,
12
	page_size_: string | undefined,
13
	filter_external_connection_id_: string | undefined,
14
	filter_telephone_number__contains_: string | undefined,
15
	filter_telephone_number__eq_: string | undefined
16
) {
17
	const url = new URL(`https://api.telnyx.com/v2/external_connections/log_messages`)
18
	for (const [k, v] of [
19
		['page[number]', page_number_],
20
		['page[size]', page_size_],
21
		['filter[external_connection_id]', filter_external_connection_id_],
22
		['filter[telephone_number][contains]', filter_telephone_number__contains_],
23
		['filter[telephone_number][eq]', filter_telephone_number__eq_]
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