0

Update an Ip connection

by
Published Apr 8, 2025

Updates settings of an existing IP connection.

Script telnyx Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Telnyx = {
3
	apiKey: string
4
}
5
/**
6
 * Update an Ip connection
7
 * Updates settings of an existing IP connection.
8
 */
9
export async function main(
10
	auth: Telnyx,
11
	id: string,
12
	body: {
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
		connection_name?: string
26
		transport_protocol?: 'UDP' | 'TCP' | 'TLS'
27
		default_on_hold_comfort_noise_enabled?: false | true
28
		dtmf_type?: 'RFC 2833' | 'Inband' | 'SIP INFO'
29
		encode_contact_header_enabled?: false | true
30
		encrypted_media?: 'SRTP'
31
		onnet_t38_passthrough_enabled?: false | true
32
		ios_push_credential_id?: string
33
		android_push_credential_id?: string
34
		webhook_event_url?: string
35
		webhook_event_failover_url?: string
36
		webhook_api_version?: '1' | '2'
37
		webhook_timeout_secs?: number
38
		rtcp_settings?: {
39
			port?: 'rtcp-mux' | 'rtp+1'
40
			capture_enabled?: false | true
41
			report_frequency_secs?: number
42
		}
43
		inbound?: {
44
			ani_number_format?: '+E.164' | 'E.164' | '+E.164-national' | 'E.164-national'
45
			dnis_number_format?: '+e164' | 'e164' | 'national' | 'sip_username'
46
			codecs?: string[]
47
			default_primary_ip_id?: string
48
			default_secondary_ip_id?: string
49
			default_tertiary_ip_id?: string
50
			default_routing_method?: 'sequential' | 'round-robin'
51
			channel_limit?: number
52
			generate_ringback_tone?: false | true
53
			isup_headers_enabled?: false | true
54
			prack_enabled?: false | true
55
			privacy_zone_enabled?: false | true
56
			sip_compact_headers_enabled?: false | true
57
			sip_region?: 'US' | 'Europe' | 'Australia'
58
			sip_subdomain?: string
59
			sip_subdomain_receive_settings?: 'only_my_connections' | 'from_anyone'
60
			timeout_1xx_secs?: number
61
			timeout_2xx_secs?: number
62
			shaken_stir_enabled?: false | true
63
		}
64
		outbound?: {
65
			call_parking_enabled?: false | true
66
			ani_override?: string
67
			ani_override_type?: 'always' | 'normal' | 'emergency'
68
			channel_limit?: number
69
			instant_ringback_enabled?: false | true
70
			generate_ringback_tone?: false | true
71
			localization?: string
72
			t38_reinvite_source?:
73
				| 'telnyx'
74
				| 'customer'
75
				| 'disabled'
76
				| 'passthru'
77
				| 'caller-passthru'
78
				| 'callee-passthru'
79
			tech_prefix?: string
80
			ip_authentication_method?: 'tech-prefixp-charge-info' | 'apiKey'
81
			ip_authentication_apiKey?: string
82
			outbound_voice_profile_id?: string
83
		}
84
	}
85
) {
86
	const url = new URL(`https://api.telnyx.com/v2/ip_connections/${id}`)
87

88
	const response = await fetch(url, {
89
		method: 'PATCH',
90
		headers: {
91
			'Content-Type': 'application/json',
92
			Authorization: 'Bearer ' + auth.apiKey
93
		},
94
		body: JSON.stringify(body)
95
	})
96
	if (!response.ok) {
97
		const text = await response.text()
98
		throw new Error(`${response.status} ${text}`)
99
	}
100
	return await response.json()
101
}
102