0

Purchase eSIMs

by
Published Apr 8, 2025

Purchases and registers the specified amount of eSIMs to the current user's account. If sim_card_group_id is provided, the eSIMs will be associated with that group. Otherwise, the default group for the current user will be used.

Script telnyx Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Telnyx = {
3
	apiKey: string
4
}
5
/**
6
 * Purchase eSIMs
7
 * Purchases and registers the specified amount of eSIMs to the current user's account.
8
If sim_card_group_id is provided, the eSIMs will be associated with that group. Otherwise, the default group for the current user will be used.
9

10
 */
11
export async function main(
12
	auth: Telnyx,
13
	body: {
14
		sim_card_group_id?: string
15
		tags?: string[]
16
		product?: string
17
		whitelabel_name?: string
18
		amount: number
19
		status?: 'enabled' | 'disabled' | 'standby'
20
	}
21
) {
22
	const url = new URL(`https://api.telnyx.com/v2/actions/purchase/esims`)
23

24
	const response = await fetch(url, {
25
		method: 'POST',
26
		headers: {
27
			'Content-Type': 'application/json',
28
			Authorization: 'Bearer ' + auth.apiKey
29
		},
30
		body: JSON.stringify(body)
31
	})
32
	if (!response.ok) {
33
		const text = await response.text()
34
		throw new Error(`${response.status} ${text}`)
35
	}
36
	return await response.json()
37
}
38