0

Get activation code for an eSIM

Published Apr 8, 2025

It returns the activation code for an eSIM. This API is only available for eSIMs. If the given SIM is a physical SIM card, or has already been installed, an error will be returned.

Script telnyx Verified

The script

Submitted by hugo697 Bun
Verified 589 days ago
1
//native
2
type Telnyx = {
3
	apiKey: string
4
}
5
/**
6
 * Get activation code for an eSIM
7
 * It returns the activation code for an eSIM.
8
 This API is only available for eSIMs. If the given SIM is a physical SIM card, or has already been installed, an error will be returned.
9

10
 */
11
export async function main(auth: Telnyx, id: string) {
12
	const url = new URL(`https://api.telnyx.com/v2/sim_cards/${id}/activation_code`)
13

14
	const response = await fetch(url, {
15
		method: 'GET',
16
		headers: {
17
			Authorization: 'Bearer ' + auth.apiKey
18
		},
19
		body: undefined
20
	})
21
	if (!response.ok) {
22
		const text = await response.text()
23
		throw new Error(`${response.status} ${text}`)
24
	}
25
	return await response.json()
26
}
27