1 | |
2 | type Telnyx = { |
3 | apiKey: string |
4 | } |
5 | |
6 | * Update a SIM card |
7 | * Updates SIM card data |
8 | */ |
9 | export async function main( |
10 | auth: Telnyx, |
11 | id: string, |
12 | body: { |
13 | id?: string |
14 | record_type?: string |
15 | status?: { |
16 | value?: |
17 | | 'registering' |
18 | | 'enabling' |
19 | | 'enabled' |
20 | | 'disabling' |
21 | | 'disabled' |
22 | | 'data_limit_exceeded' |
23 | | 'setting_standby' |
24 | | 'standby' |
25 | reason?: string |
26 | } |
27 | type?: 'physical' | 'esim' |
28 | iccid?: string |
29 | imsi?: string |
30 | msisdn?: string |
31 | sim_card_group_id?: string |
32 | tags?: string[] |
33 | authorized_imeis?: string[] |
34 | current_imei?: string |
35 | data_limit?: { amount?: string; unit?: 'MB' | 'GB' } |
36 | current_billing_period_consumed_data?: { amount?: string; unit?: string } |
37 | actions_in_progress?: false | true |
38 | created_at?: string |
39 | updated_at?: string |
40 | ipv4?: string |
41 | ipv6?: string |
42 | current_device_location?: { |
43 | latitude?: string |
44 | longitude?: string |
45 | accuracy?: number |
46 | accuracy_unit?: string |
47 | } |
48 | current_mnc?: string |
49 | current_mcc?: string |
50 | live_data_session?: 'connected' | 'disconnected' | 'unknown' |
51 | } |
52 | ) { |
53 | const url = new URL(`https://api.telnyx.com/v2/sim_cards/${id}`) |
54 |
|
55 | const response = await fetch(url, { |
56 | method: 'PATCH', |
57 | headers: { |
58 | 'Content-Type': 'application/json', |
59 | Authorization: 'Bearer ' + auth.apiKey |
60 | }, |
61 | body: JSON.stringify(body) |
62 | }) |
63 | if (!response.ok) { |
64 | const text = await response.text() |
65 | throw new Error(`${response.status} ${text}`) |
66 | } |
67 | return await response.json() |
68 | } |
69 |
|