0

Create a customer service record

by
Published Apr 8, 2025

Create a new customer service record for the provided phone number.

Script telnyx Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Telnyx = {
3
	apiKey: string
4
}
5
/**
6
 * Create a customer service record
7
 * Create a new customer service record for the provided phone number.
8
 */
9
export async function main(
10
	auth: Telnyx,
11
	body: {
12
		phone_number: string
13
		webhook_url?: string
14
		additional_data?: {
15
			name?: string
16
			authorized_person_name?: string
17
			pin?: string
18
			account_number?: string
19
			customer_code?: string
20
			address_line_1?: string
21
			city?: string
22
			state?: string
23
			zip_code?: string
24
			billing_phone_number?: string
25
		}
26
	}
27
) {
28
	const url = new URL(`https://api.telnyx.com/v2/customer_service_records`)
29

30
	const response = await fetch(url, {
31
		method: 'POST',
32
		headers: {
33
			'Content-Type': 'application/json',
34
			Authorization: 'Bearer ' + auth.apiKey
35
		},
36
		body: JSON.stringify(body)
37
	})
38
	if (!response.ok) {
39
		const text = await response.text()
40
		throw new Error(`${response.status} ${text}`)
41
	}
42
	return await response.json()
43
}
44