Service Pre-Authorization
Endpoint:
https://api.betatel.com/api/billing/services/preauth
Method: POST
Description: Verify if a user has sufficient funds for a service and create a billing event.
Request Headers
The request must include an Authorization header with a valid API key for authentication:
Header | Value | Required | Description |
---|---|---|---|
x-api-key | {{x-api-key}} | Yes | The authentication api key to verify the user's identity |
Request Body
Your request should contain the userId,serviceId,phoneNumber,quantity:
{
"userId": "rzeureu2626323232",
"serviceId": "svc_mobile_sms",
"phoneNumber": "+4412345678",
"quantity": 150
}
Param | Value | Type | Required | Description |
---|---|---|---|---|
userId | rzeureu2626323232 | String | Yes | The user's Id |
serviceId | svc_mobile_sms | String | Yes | The service Id |
phoneNumber | +4412345678 | String | Yes | Phone nymber |
quantity | 150 | Int | Yes | Quantity |
Let’s Dive Into the Code!
Choose your preferred programming language and use the provided examples to integrate the post service pre-Authorization.
- cUrl
- Python
- Node.js
- PHP
- Java
- C#
Example - cURL
curl --location 'https://api.betatel.com/api/billing/services/preauth' \
--header 'Content-Type: application/json' \
--header 'x-api-key: ••••••' \
--data '{
"userId": "rzeureu2626323232",
"serviceId": "svc_mobile_sms",
"phoneNumber": "+4412345678",
"quantity": 150
}'
Example - Python
import http.client
import json
conn = http.client.HTTPSConnection("api.betatel.com")
payload = json.dumps({
"userId": "rzeureu2626323232",
"serviceId": "svc_mobile_sms",
"phoneNumber": "+4412345678",
"quantity": 150
})
headers = {
'Content-Type': 'application/json',
'x-api-key': 'C8FdQrQKxXiLvUtEoyLobJopZwZhalPhdoDr9qVxACBI'
}
conn.request("POST", "/api/billing/services/preauth", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
Example - Node.js
const axios = require('axios');
let data = JSON.stringify({
"userId": "rzeureu2626323232",
"serviceId": "svc_mobile_sms",
"phoneNumber": "+4412345678",
"quantity": 150
});
let config = {
method: 'post',
maxBodyLength: Infinity,
url: 'https://api.betatel.com/api/billing/services/preauth',
headers: {
'Content-Type': 'application/json',
'x-api-key': '••••••'
},
data : data
};
axios.request(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
console.log(error);
});
Example - PHP
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.betatel.com/api/billing/services/preauth',
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 =>'{
"userId": "rzeureu2626323232",
"serviceId": "svc_mobile_sms",
"phoneNumber": "+4412345678",
"quantity": 150
}',
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'x-api-key: ••••••'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Example - Java
Unirest.setTimeouts(0, 0);
HttpResponse<String> response = Unirest.post("https://api.betatel.com/api/billing/services/preauth")
.header("Content-Type", "application/json")
.header("x-api-key", "••••••")
.body("{\n \"userId\": \"rzeureu2626323232\",\n \"serviceId\": \"svc_mobile_sms\",\n \"phoneNumber\": \"+4412345678\",\n \"quantity\": 150\n}")
.asString();
Example - C#
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://api.betatel.com/api/billing/services/preauth");
request.Headers.Add("x-api-key", "••••••");
var content = new StringContent("{\n \"userId\": \"rzeureu2626323232\",\n \"serviceId\": \"svc_mobile_sms\",\n \"phoneNumber\": \"+4412345678\",\n \"quantity\": 150\n}", null, "application/json");
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
Response
JSON Schema:
{
"correlationId": "evt_b4f82932",
"userId": "user123",
"serviceId": "svc_mobile_sms",
"status": "AUTHORIZED",
"estimatedCost": 1.80,
"currency": "USD",
"timestamp": "2025-03-18T14:32:05Z"
}
Field | Type | Description |
---|---|---|
correlationId | string | A unique identifier for the authorization request (e.g., "evt_b4f82932"). |
userId | string | The unique identifier for the user (e.g., "user123"). |
serviceId | string | The identifier for the service being authorized (e.g., "svc_mobile_sms"). |
status | string | The authorization status of the request (e.g., "AUTHORIZED"). |
estimatedCost | number | The estimated cost for the service (e.g., 1.80). |
currency | string | The currency in which the estimated cost is represented (e.g., "USD"). |
timestamp | string | The timestamp of when the authorization was processed (e.g., "2025-03-18T14:32:05Z"). |