0

Update a credential connection

by
Published Apr 8, 2025

Updates settings of an existing credential 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 a credential connection
7
 * Updates settings of an existing credential connection.
8
 */
9
export async function main(
10
	auth: Telnyx,
11
	id: string,
12
	body: {
13
		active?: false | true
14
		user_name?: string
15
		password?: string
16
		anchorsite_override?:
17
			| 'Latency'
18
			| 'Chicago, IL'
19
			| 'Ashburn, VA'
20
			| 'San Jose, CA'
21
			| 'Sydney, Australia'
22
			| 'Amsterdam, Netherlands'
23
			| 'London, UK'
24
			| 'Toronto, Canada'
25
			| 'Vancouver, Canada'
26
			| 'Frankfurt, Germany'
27
		connection_name?: string
28
		sip_uri_calling_preference?: 'disabled' | 'unrestricted' | 'internal'
29
		default_on_hold_comfort_noise_enabled?: false | true
30
		dtmf_type?: 'RFC 2833' | 'Inband' | 'SIP INFO'
31
		encode_contact_header_enabled?: false | true
32
		encrypted_media?: 'SRTP'
33
		onnet_t38_passthrough_enabled?: false | true
34
		ios_push_credential_id?: string
35
		android_push_credential_id?: string
36
		webhook_event_url?: string
37
		webhook_event_failover_url?: string
38
		webhook_api_version?: '1' | '2'
39
		webhook_timeout_secs?: number
40
		rtcp_settings?: {
41
			port?: 'rtcp-mux' | 'rtp+1'
42
			capture_enabled?: false | true
43
			report_frequency_secs?: number
44
		}
45
		inbound?: {
46
			ani_number_format?: '+E.164' | 'E.164' | '+E.164-national' | 'E.164-national'
47
			dnis_number_format?: '+e164' | 'e164' | 'national' | 'sip_username'
48
			codecs?: string[]
49
			channel_limit?: number
50
			generate_ringback_tone?: false | true
51
			isup_headers_enabled?: false | true
52
			prack_enabled?: false | true
53
			privacy_zone_enabled?: false | true
54
			sip_compact_headers_enabled?: false | true
55
			timeout_1xx_secs?: number
56
			timeout_2xx_secs?: string
57
			shaken_stir_enabled?: false | true
58
		}
59
		outbound?: {
60
			call_parking_enabled?: false | true
61
			ani_override?: string
62
			ani_override_type?: 'always' | 'normal' | 'emergency'
63
			channel_limit?: number
64
			instant_ringback_enabled?: false | true
65
			generate_ringback_tone?: false | true
66
			localization?: string
67
			t38_reinvite_source?:
68
				| 'disabled'
69
				| 'telnyx'
70
				| 'customer'
71
				| 'passthru'
72
				| 'caller-passthru'
73
				| 'callee-passthru'
74
			outbound_voice_profile_id?: string
75
		}
76
	}
77
) {
78
	const url = new URL(`https://api.telnyx.com/v2/credential_connections/${id}`)
79

80
	const response = await fetch(url, {
81
		method: 'PATCH',
82
		headers: {
83
			'Content-Type': 'application/json',
84
			Authorization: 'Bearer ' + auth.apiKey
85
		},
86
		body: JSON.stringify(body)
87
	})
88
	if (!response.ok) {
89
		const text = await response.text()
90
		throw new Error(`${response.status} ${text}`)
91
	}
92
	return await response.json()
93
}
94