1 | |
2 | type Telnyx = { |
3 | apiKey: string |
4 | } |
5 | |
6 | * Update a phone number |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Telnyx, |
11 | id: string, |
12 | body: { |
13 | id?: string |
14 | tags?: string[] |
15 | external_pin?: string |
16 | hd_voice_enabled?: false | true |
17 | customer_reference?: string |
18 | connection_id?: string |
19 | billing_group_id?: string |
20 | number_level_routing?: 'disabled' |
21 | } |
22 | ) { |
23 | const url = new URL(`https://api.telnyx.com/v2/phone_numbers/${id}`) |
24 |
|
25 | const response = await fetch(url, { |
26 | method: 'PATCH', |
27 | headers: { |
28 | 'Content-Type': 'application/json', |
29 | Authorization: 'Bearer ' + auth.apiKey |
30 | }, |
31 | body: JSON.stringify(body) |
32 | }) |
33 | if (!response.ok) { |
34 | const text = await response.text() |
35 | throw new Error(`${response.status} ${text}`) |
36 | } |
37 | return await response.json() |
38 | } |
39 |
|