0

Preview the LOA configuration parameters

by
Published Apr 8, 2025

Preview the LOA template that would be generated without need to create LOA configuration.

Script telnyx Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Telnyx = {
3
	apiKey: string
4
}
5
/**
6
 * Preview the LOA configuration parameters
7
 * Preview the LOA template that would be generated without need to create LOA configuration.
8
 */
9
export async function main(
10
	auth: Telnyx,
11
	body: {
12
		name: string
13
		logo: { document_id: string }
14
		company_name: string
15
		address: {
16
			street_address: string
17
			extended_address?: string
18
			city?: string
19
			state?: string
20
			zip_code?: string
21
			country_code: string
22
		}
23
		contact: { email: string; phone_number: string }
24
	}
25
) {
26
	const url = new URL(`https://api.telnyx.com/v2/porting/loa_configuration/preview`)
27

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