POST Create Package
This endpoint creates a new package for a specific SIM card using a package template.
Configure the API Endpoint
https://esim.betatel.com/api/v1/esim/packages
- Method:
POST
Set Up the Headers
| Param | Value | Description |
|---|---|---|
| Content-Type | application/json | Specifies the payload format. |
| x-api-key | {{x-api-key}} | Your unique API key for secure access. |
| x-user-id | {{x-user-id}} | Your user identifier for added security and tracking. |
Request Body
Info: Ensure each field in the request is validated and cross-referenced with existing data for consistency.
Request Body Example
{
"sim": "89148000004012345678",
"package_template": 21145354,
"time_allowance": 604800
}
Parameters
| Param | Type | Required | Description |
|---|---|---|---|
| sim | string | required | The ICCID of the SIM card |
| package_template | integer | required | The package template ID to use |
| time_allowance | integer | optional | Optional time allowance in seconds |
Example Response
Status Code: 201 Created
Content-Type: application/json
Example Response
{
"id": "pkg_789012",
"sim": "8910300000045681955",
"package_template": 21145354,
"status": "NOT_ACTIVE",
"created_date": 1761330317000,
"time_allowance": 604800
}
The response includes the id - unique package identifier, sim - associated SIM ICCID, package_template - template used, and status - current package status.
Code Snippets
Hint: Use code snippets for reference on different programming environments. Customize the examples as needed.
- cUrl
- Python
- Node.js
- PHP
- Java
- C#
Example - cURL
curl --location 'https://esim.betatel.com/api/v1/esim/packages' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header 'x-api-key: {{x-api-key}}' \
--header 'x-user-id: {{x-user-id}}' \
--data '{
"sim": "89148000004012345678",
"package_template": 21145354,
"time_allowance": 604800
}'
Example - Python
import http.client
import json
conn = http.client.HTTPSConnection("esim.betatel.com")
payload = json.dumps({
"sim": "89148000004012345678",
"package_template": 21145354,
"time_allowance": 604800
})
headers = {
'Accept': 'application/json',
'Content-Type': 'application/json',
'x-api-key': '{{x-api-key}}',
'x-user-id': '{{x-user-id}}'
}
conn.request("POST", "/api/v1/esim/packages", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
Example - Node.js
const axios = require('axios');
const data = {
sim: "89148000004012345678",
package_template: 21145354,
time_allowance: 604800
};
axios.post('https://esim.betatel.com/api/v1/esim/packages', data, {
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'x-api-key': '{{x-api-key}}',
'x-user-id': '{{x-user-id}}'
}
})
.then((response) => {
console.log(response.data);
})
.catch((error) => {
console.log(error);
});
Example - PHP
<?php
$curl = curl_init();
$data = [
"sim" => "89148000004012345678",
"package_template" => 21145354,
"time_allowance" => 604800
];
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://esim.betatel.com/api/v1/esim/packages',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => json_encode($data),
CURLOPT_HTTPHEADER => array(
'Accept: application/json',
'Content-Type: application/json',
'x-api-key: {{x-api-key}}',
'x-user-id: {{x-user-id}}'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Example - Java
HttpResponse<String> response = Unirest.post("https://esim.betatel.com/api/v1/esim/packages")
.header("Accept", "application/json")
.header("Content-Type", "application/json")
.header("x-api-key", "{{x-api-key}}")
.header("x-user-id", "{{x-user-id}}")
.body("{\"sim\":\"89148000004012345678\",\"package_template\":21145354,\"time_allowance\":604800}")
.asString();
System.out.println(response.getBody());
Example - C#
var client = new HttpClient();
var data = new StringContent(JsonConvert.SerializeObject(new {
sim = "89148000004012345678",
package_template = 21145354,
time_allowance = 604800
}), Encoding.UTF8, "application/json");
var request = new HttpRequestMessage(HttpMethod.Post, "https://esim.betatel.com/api/v1/esim/packages")
{
Content = data
};
request.Headers.Add("Accept", "application/json");
request.Headers.Add("x-api-key", "{{x-api-key}}");
request.Headers.Add("x-user-id", "{{x-user-id}}"
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
Error Handling
Important: Attempting to create a package with an invalid or non-existent SIM or template ID will result in errors such as '404'.
- 400 - Bad Request - Invalid input parameters
- 404 - Not Found - SIM or package template not found
- 401 - Unauthorized - Invalid or missing API key