0

Creates an External Connection

by
Published Apr 8, 2025

Creates a new External Connection based on the parameters sent in the request. The external_sip_connection and outbound voice profile id are required. Once created, you can assign phone numbers to your application using the `/phone_numbers` endpoint.

Script telnyx Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Telnyx = {
3
	apiKey: string
4
}
5
/**
6
 * Creates an External Connection
7
 * Creates a new External Connection based on the parameters sent in the request. The external_sip_connection and outbound voice profile id are required. Once created, you can assign phone numbers to your application using the `/phone_numbers` endpoint.
8
 */
9
export async function main(
10
	auth: Telnyx,
11
	body: {
12
		active?: false | true
13
		external_sip_connection: 'zoom'
14
		webhook_event_url?: string
15
		webhook_event_failover_url?: string
16
		webhook_timeout_secs?: number
17
		inbound?: { channel_limit?: number }
18
		outbound?: { channel_limit?: number; outbound_voice_profile_id?: string }
19
	}
20
) {
21
	const url = new URL(`https://api.telnyx.com/v2/external_connections`)
22

23
	const response = await fetch(url, {
24
		method: 'POST',
25
		headers: {
26
			'Content-Type': 'application/json',
27
			Authorization: 'Bearer ' + auth.apiKey
28
		},
29
		body: JSON.stringify(body)
30
	})
31
	if (!response.ok) {
32
		const text = await response.text()
33
		throw new Error(`${response.status} ${text}`)
34
	}
35
	return await response.json()
36
}
37