0

Creates an address

by
Published Apr 8, 2025

Creates an address.

Script telnyx Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Telnyx = {
3
	apiKey: string
4
}
5
/**
6
 * Creates an address
7
 * Creates an address.
8
 */
9
export async function main(
10
	auth: Telnyx,
11
	body: {
12
		customer_reference?: string
13
		first_name: string
14
		last_name: string
15
		business_name: string
16
		phone_number?: string
17
		street_address: string
18
		extended_address?: string
19
		locality: string
20
		administrative_area?: string
21
		neighborhood?: string
22
		borough?: string
23
		postal_code?: string
24
		country_code: string
25
		address_book?: false | true
26
		validate_address?: false | true
27
	}
28
) {
29
	const url = new URL(`https://api.telnyx.com/v2/addresses`)
30

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