0

List all active calls for given connection

by
Published Apr 8, 2025

Lists all active calls for given connection. Acceptable connections are either SIP connections with webhook_url or xml_request_url, call control or texml. Returned results are cursor paginated.

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 active calls for given connection
7
 * Lists all active calls for given connection. Acceptable connections are either SIP connections with webhook_url or xml_request_url, call control or texml. Returned results are cursor paginated.
8

9
 */
10
export async function main(
11
	auth: Telnyx,
12
	connection_id: string,
13
	page_limit_: string | undefined,
14
	page_after_: string | undefined,
15
	page_before_: string | undefined
16
) {
17
	const url = new URL(`https://api.telnyx.com/v2/connections/${connection_id}/active_calls`)
18
	for (const [k, v] of [
19
		['page[limit]', page_limit_],
20
		['page[after]', page_after_],
21
		['page[before]', page_before_]
22
	]) {
23
		if (v !== undefined && v !== '' && k !== undefined) {
24
			url.searchParams.append(k, v)
25
		}
26
	}
27
	const response = await fetch(url, {
28
		method: 'GET',
29
		headers: {
30
			Authorization: 'Bearer ' + auth.apiKey
31
		},
32
		body: undefined
33
	})
34
	if (!response.ok) {
35
		const text = await response.text()
36
		throw new Error(`${response.status} ${text}`)
37
	}
38
	return await response.json()
39
}
40