0

Create a Verify profile

by
Published Apr 8, 2025

Creates a new Verify profile to associate verifications with.

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 Verify profile
7
 * Creates a new Verify profile to associate verifications with.
8
 */
9
export async function main(
10
	auth: Telnyx,
11
	body: {
12
		name: string
13
		webhook_url?: string
14
		webhook_failover_url?: string
15
		sms?: {
16
			messaging_template_id?: string
17
			app_name?: string
18
			alpha_sender?: string
19
			code_length?: number
20
			whitelisted_destinations: string[]
21
			default_verification_timeout_secs?: number
22
		}
23
		call?: {
24
			messaging_template_id?: string
25
			app_name?: string
26
			code_length?: number
27
			whitelisted_destinations?: string[]
28
			default_verification_timeout_secs?: number
29
		}
30
		flashcall?: {
31
			whitelisted_destinations?: string[]
32
			default_verification_timeout_secs?: number
33
		}
34
		language?: string
35
	}
36
) {
37
	const url = new URL(`https://api.telnyx.com/v2/verify_profiles`)
38

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