1 | |
2 | type Telnyx = { |
3 | apiKey: string |
4 | } |
5 | |
6 | * Create Advanced Order |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Telnyx, |
11 | body: { |
12 | country_code?: string |
13 | comments?: string |
14 | quantity?: number |
15 | area_code?: string |
16 | phone_number_type?: |
17 | | (string & 'local') |
18 | | 'mobile' |
19 | | 'toll_free' |
20 | | 'shared_cost' |
21 | | 'national' |
22 | | 'landline'[] |
23 | features?: 'sms' | 'mms' | 'voice' | 'fax' | 'emergency'[] |
24 | customer_reference?: string |
25 | } |
26 | ) { |
27 | const url = new URL(`https://api.telnyx.com/v2/advanced_orders`) |
28 |
|
29 | const response = await fetch(url, { |
30 | method: 'POST', |
31 | headers: { |
32 | 'Content-Type': 'application/json', |
33 | Authorization: 'Bearer ' + auth.apiKey |
34 | }, |
35 | body: JSON.stringify(body) |
36 | }) |
37 | if (!response.ok) { |
38 | const text = await response.text() |
39 | throw new Error(`${response.status} ${text}`) |
40 | } |
41 | return await response.json() |
42 | } |
43 |
|