Packages API
Overview
The Packages API provides comprehensive functionalities for managing packages, including creating, retrieving, activating, and terminating packages for SIM cards with flexible filtering options.
getPackages
This method returns a paginated and filtered list of packages.
Parameters
- count (optional): Number of items to return
- offset (optional): Number of items to skip
- inventory (optional): Filter by inventory ID
- packageTemplate (optional): Filter by package template ID
- sim (optional): Filter by SIM ICCID
- status (optional): Filter by package status ('NOT_ACTIVE' | 'ACTIVE' | 'SUSPENDED' | 'TERMINATED')
Return Type:
GetPackagesResponse
Authorization:
- Requires
ApiUserIdandApiKeyAuth
Example
Here's how to use the Packages API to fetch packages:
import { PackagesApi, Configuration } from '@betatelltd/esim-sdk';
const config = new Configuration({
apiKey: (name: string) => {
if (name === 'x-api-key') return 'your-api-key';
if (name === 'x-user-id') return 'your-user-id';
return '';
},
basePath: 'base-url',
});
const apiInstance = new PackagesApi(configuration);
let count: number; // Number of items to return (optional) (default to undefined)
let offset: number; // Number of items to skip (optional) (default to undefined)
let inventory: number; // Filter by inventory ID (optional) (default to undefined)
let packageTemplate: number; // Filter by package template ID (optional) (default to undefined)
let sim: string; // Filter by SIM ICCID (optional) (default to undefined)
let status: 'NOT_ACTIVE' | 'ACTIVE' | 'SUSPENDED' | 'TERMINATED'; // Filter by package status (optional) (default to undefined)
const { status, data } = await apiInstance.getPackages(
count,
offset,
inventory,
packageTemplate,
sim,
status
);
Response Codes
- 200: Success
- 400: Bad Request - Invalid parameters
- 401: Unauthorized - Invalid or missing API key
- 500: Internal Server Error
GetPackagesResponse
The GetPackagesResponse object contains the following properties:
| Name | Type | Description | Notes |
|---|---|---|---|
| total | number | Total number of packages available | [default to undefined] |
| count | number | Number of items returned in this response | [default to undefined] |
| offset | number | Number of items skipped | [default to undefined] |
| packages | Package[] | Array of package objects | [default to undefined] |
Example
import { GetPackagesResponse } from '@betatelltd/esim-sdk';
const instance: GetPackagesResponse = {
total,
count,
offset,
packages,
};
getPackage
This method returns detailed information about a specific package.
Parameters
- id (required): Package ID
Return Type:
Package
Authorization:
- Requires
ApiUserIdandApiKeyAuth
Example
Here's how to use the Packages API to fetch a specific package:
import { PackagesApi, Configuration } from '@betatelltd/esim-sdk';
const config = new Configuration({
apiKey: (name: string) => {
if (name === 'x-api-key') return 'your-api-key';
if (name === 'x-user-id') return 'your-user-id';
return '';
},
basePath: 'base-url',
});
const apiInstance = new PackagesApi(configuration);
let id: string; // Package ID (default to undefined)
const { status, data } = await apiInstance.getPackage(id);
Response Codes
- 200: Success
- 400: Bad Request - Invalid ID
- 401: Unauthorized - Invalid or missing API key
- 404: Not Found - Package not found
- 500: Internal Server Error
createPackage
This method creates a new package for a specific SIM card.
Parameters
- createPackageRequest (required): CreatePackageRequest object
Return Type:
CreatePackageResponse
Authorization:
- Requires
ApiUserIdandApiKeyAuth
Example
Here's how to use the Packages API to create a package:
import { PackagesApi, Configuration, CreatePackageRequest } from '@betatelltd/esim-sdk';
const config = new Configuration({
apiKey: (name: string) => {
if (name === 'x-api-key') return 'your-api-key';
if (name === 'x-user-id') return 'your-user-id';
return '';
},
basePath: 'base-url',
});
const apiInstance = new PackagesApi(configuration);
let createPackageRequest: CreatePackageRequest; //
const { status, data } = await apiInstance.createPackage(
createPackageRequest
);
Response Codes
- 201: Package created successfully
- 400: Bad Request - Invalid input parameters
- 401: Unauthorized - Invalid or missing API key
- 409: Conflict - Package already exists for this SIM
- 500: Internal Server Error
CreatePackageRequest
The CreatePackageRequest object contains the following properties:
| Name | Type | Description | Notes |
|---|---|---|---|
| sim | string | The ICCID of the SIM card | [default to undefined] |
| package_template | number | The package template ID | [default to undefined] |
| time_allowance | number | Optional time allowance in seconds | [optional] [default to undefined] |
Example
import { CreatePackageRequest } from '@betatelltd/esim-sdk';
const instance: CreatePackageRequest = {
sim,
package_template,
time_allowance,
};
CreatePackageResponse
The CreatePackageResponse object contains the following properties:
| Name | Type | Description | Notes |
|---|---|---|---|
| id | string | Created package ID | [default to undefined] |
| sim | string | SIM ICCID | [default to undefined] |
| created_date | number | Unix timestamp of package creation | [default to undefined] |
| expiry_date | number | Unix timestamp of package expiry | [default to undefined] |
| activated_date | number | Unix timestamp when package was activated (0 if not activated) | [default to undefined] |
| terminated_date | number | Unix timestamp when package was terminated (0 if not terminated) | [default to undefined] |
| window_activation_start | number | Unix timestamp of activation window start | [default to undefined] |
| window_activation_end | number | Unix timestamp of activation window end | [default to undefined] |
| status | string | Current package status | [default to undefined] |
| voice_usage_remaining | number | Remaining voice minutes | [default to undefined] |
| data_usage_remaining | number | Remaining data in bytes | [default to undefined] |
| sms_usage_remaining | number | Remaining SMS count | [default to undefined] |
| time_allowance | number | Time allowance in seconds | [default to undefined] |
| package_template | object | Package template details | [default to undefined] |
| apn | string | Access Point Name | [default to undefined] |
Example
import { CreatePackageResponse } from '@betatelltd/esim-sdk';
const instance: CreatePackageResponse = {
id,
sim,
created_date,
expiry_date,
activated_date,
terminated_date,
window_activation_start,
window_activation_end,
status,
voice_usage_remaining,
data_usage_remaining,
sms_usage_remaining,
time_allowance,
package_template,
apn,
};
activatePackage
This method activates a specific package for use.
Parameters
- id (required): Package ID to activate
Return Type:
boolean
Authorization:
- Requires
ApiUserIdandApiKeyAuth
Example
Here's how to use the Packages API to activate a package:
import { PackagesApi, Configuration } from '@betatelltd/esim-sdk';
const config = new Configuration({
apiKey: (name: string) => {
if (name === 'x-api-key') return 'your-api-key';
if (name === 'x-user-id') return 'your-user-id';
return '';
},
basePath: 'base-url',
});
const apiInstance = new PackagesApi(configuration);
let id: string; // Package ID to activate (default to undefined)
const { status, data } = await apiInstance.activatePackage(id);
Response Codes
- 204: Package activated successfully (no content)
- 400: Bad Request - Invalid ID or package cannot be activated
- 401: Unauthorized - Invalid or missing API key
- 404: Not Found - Package not found
- 500: Internal Server Error
terminatePackage
This method terminates an active package.
Parameters
- id (required): Package ID to terminate
Return Type:
boolean
Authorization:
- Requires
ApiUserIdandApiKeyAuth
Example
Here's how to use the Packages API to terminate a package:
import { PackagesApi, Configuration } from '@betatelltd/esim-sdk';
const config = new Configuration({
apiKey: (name: string) => {
if (name === 'x-api-key') return 'your-api-key';
if (name === 'x-user-id') return 'your-user-id';
return '';
},
basePath: 'base-url',
});
const apiInstance = new PackagesApi(configuration);
let id: string; // Package ID to terminate (default to undefined)
const { status, data } = await apiInstance.terminatePackage(id);
Response Codes
- 204: Package terminated successfully (no content)
- 400: Bad Request - Invalid ID or package cannot be terminated
- 401: Unauthorized - Invalid or missing API key
- 404: Not Found - Package not found
- 500: Internal Server Error