0

Creates a Fax Application

by
Published Apr 8, 2025

Creates a new Fax Application based on the parameters sent in the request. The application name and webhook URL 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 a Fax Application
7
 * Creates a new Fax Application based on the parameters sent in the request. The application name and webhook URL 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
		application_name: string
13
		active?: false | true
14
		anchorsite_override?:
15
			| 'Latency'
16
			| 'Chicago, IL'
17
			| 'Ashburn, VA'
18
			| 'San Jose, CA'
19
			| 'Sydney, Australia'
20
			| 'Amsterdam, Netherlands'
21
			| 'London, UK'
22
			| 'Toronto, Canada'
23
			| 'Vancouver, Canada'
24
			| 'Frankfurt, Germany'
25
		webhook_event_url: string
26
		webhook_event_failover_url?: string
27
		webhook_timeout_secs?: number
28
		inbound?: {
29
			channel_limit?: number
30
			sip_subdomain?: string
31
			sip_subdomain_receive_settings?: 'only_my_connections' | 'from_anyone'
32
		}
33
		outbound?: { channel_limit?: number; outbound_voice_profile_id?: string }
34
	}
35
) {
36
	const url = new URL(`https://api.telnyx.com/v2/fax_applications`)
37

38
	const response = await fetch(url, {
39
		method: 'POST',
40
		headers: {
41
			'Content-Type': 'application/json',
42
			Authorization: 'Bearer ' + auth.apiKey
43
		},
44
		body: JSON.stringify(body)
45
	})
46
	if (!response.ok) {
47
		const text = await response.text()
48
		throw new Error(`${response.status} ${text}`)
49
	}
50
	return await response.json()
51
}
52