//native
type Telnyx = {
apiKey: string
}
/**
* Request setting a SIM card public IP
* 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.
*/
export async function main(auth: Telnyx, id: string, region_code: string | undefined) {
const url = new URL(`https://api.telnyx.com/v2/sim_cards/${id}/actions/set_public_ip`)
for (const [k, v] of [['region_code', region_code]]) {
if (v !== undefined && v !== '' && k !== undefined) {
url.searchParams.append(k, v)
}
}
const response = await fetch(url, {
method: 'POST',
headers: {
Authorization: 'Bearer ' + auth.apiKey
},
body: undefined
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.json()
}
Submitted by hugo697 428 days ago