0

Request setting a SIM card public IP

by
Published Apr 8, 2025

This API makes a SIM card reachable on the public internet by mapping a random public IP to the SIM card. The API will trigger an asynchronous operation called a SIM Card Action. The status of the SIM Card Action can be followed through the [List SIM Card Action](https://developersdev.telnyx.com/docs/api/v2/wireless/SIM-Card-Actions#ListSIMCardActions) API. Setting a Public IP to a SIM Card incurs a charge and will only succeed if the account has sufficient funds.

Script telnyx Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Telnyx = {
3
	apiKey: string
4
}
5
/**
6
 * Request setting a SIM card public IP
7
 * This API makes a SIM card reachable on the public internet by mapping a random public IP to the SIM card. 
8
 The API will trigger an asynchronous operation called a SIM Card Action. The status of the SIM Card Action can be followed through the [List SIM Card Action](https://developersdev.telnyx.com/docs/api/v2/wireless/SIM-Card-Actions#ListSIMCardActions) API. 
9
 Setting a Public IP to a SIM Card incurs a charge and will only succeed if the account has sufficient funds.
10
 */
11
export async function main(auth: Telnyx, id: string, region_code: string | undefined) {
12
	const url = new URL(`https://api.telnyx.com/v2/sim_cards/${id}/actions/set_public_ip`)
13
	for (const [k, v] of [['region_code', region_code]]) {
14
		if (v !== undefined && v !== '' && k !== undefined) {
15
			url.searchParams.append(k, v)
16
		}
17
	}
18
	const response = await fetch(url, {
19
		method: 'POST',
20
		headers: {
21
			Authorization: 'Bearer ' + auth.apiKey
22
		},
23
		body: undefined
24
	})
25
	if (!response.ok) {
26
		const text = await response.text()
27
		throw new Error(`${response.status} ${text}`)
28
	}
29
	return await response.json()
30
}
31