POST Telegram Stats
This endpoint returns aggregated statistics for Telegram messages sent from your account within a specified time range. Use it to monitor delivery performance, track message volumes, and analyse trends across different time intervals.
Configure the API Endpoint
https://api.betatel.com/api/v1/connect-hub/telegram/stats
- Method:
POST
Set Up the Headers
| Param | Value | Description |
|---|---|---|
| Content-type | application/json | Specifies the payload format. |
| x-api-key | {{x-api-key}} | API key for authorization. |
| x-account-id | {{x-account-id}} | User identifier for added security and tracking. |
Craft the Request Body
Example of body
{
"type": "daily",
"start_time": "2024-01-01T00:00:00.000Z",
"end_time": "2024-01-31T23:59:59.000Z",
"timezone": "UTC"
}
| Field | Type | Required | Description |
|---|---|---|---|
| type | string | No | The aggregation interval (default: today). See supported types below. |
| start_time | string | No | Start of the reporting period in ISO 8601 format. |
| end_time | string | No | End of the reporting period in ISO 8601 format. |
| timezone | string | No | Timezone for date grouping (default: "UTC"). |
Supported Stat Types
| Type | Description |
|---|---|
today | Aggregated totals for the current day. |
hourly | Grouped by hour within the specified range. |
daily | Grouped by day within the specified range. |
weekly | Grouped by week within the specified range. |
monthly | Grouped by month within the specified range. |
yearly | Grouped by year within the specified range. |
lasth | Aggregated totals for the last 60 minutes. |
last12h | Aggregated totals for the last 12 hours. |
last24h | Aggregated totals for the last 24 hours. |
last30m | Aggregated totals for the last 30 minutes. |
last10m | Aggregated totals for the last 10 minutes. |
last5m | Aggregated totals for the last 5 minutes. |
lastm | Aggregated totals for the last 1 minute. |
lastmonth | Aggregated totals for the last 30 days. |
Code Snippets
- cUrl
- Python
- Node.js
- PHP
- Java
- C#
Example - cURL
curl --location 'https://api.betatel.com/api/v1/connect-hub/telegram/stats' \
--header 'Content-Type: application/json' \
--header 'x-api-key: YOUR_API_KEY' \
--header 'x-account-id: YOUR_ACCOUNT_ID' \
--data '{
"type": "daily",
"start_time": "2024-01-01T00:00:00.000Z",
"end_time": "2024-01-31T23:59:59.000Z",
"timezone": "UTC"
}'
Example - Python
import http.client
import json
conn = http.client.HTTPSConnection("api.betatel.com")
payload = json.dumps({
"type": "daily",
"start_time": "2024-01-01T00:00:00.000Z",
"end_time": "2024-01-31T23:59:59.000Z",
"timezone": "UTC"
})
headers = {
'Content-Type': 'application/json',
'x-api-key': 'YOUR_API_KEY',
'x-account-id': 'YOUR_ACCOUNT_ID'
}
conn.request("POST", "/api/v1/connect-hub/telegram/stats", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
Example - Node.js
const axios = require('axios');
let data = JSON.stringify({
"type": "daily",
"start_time": "2024-01-01T00:00:00.000Z",
"end_time": "2024-01-31T23:59:59.000Z",
"timezone": "UTC"
});
let config = {
method: 'post',
maxBodyLength: Infinity,
url: 'https://api.betatel.com/api/v1/connect-hub/telegram/stats',
headers: {
'Content-Type': 'application/json',
'x-api-key': 'YOUR_API_KEY',
'x-account-id': 'YOUR_ACCOUNT_ID'
},
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/v1/connect-hub/telegram/stats',
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 => '{"type":"daily","start_time":"2024-01-01T00:00:00.000Z","end_time":"2024-01-31T23:59:59.000Z","timezone":"UTC"}',
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'x-api-key: YOUR_API_KEY',
'x-account-id: YOUR_ACCOUNT_ID'
),
));
$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/v1/connect-hub/telegram/stats")
.header("Content-Type", "application/json")
.header("x-api-key", "YOUR_API_KEY")
.header("x-account-id", "YOUR_ACCOUNT_ID")
.body("{\"type\":\"DAILY\",\"start_time\":\"2024-01-01T00:00:00.000Z\",\"end_time\":\"2024-01-31T23:59:59.000Z\",\"timezone\":\"UTC\"}")
.asString();
Example - C#
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://api.betatel.com/api/v1/connect-hub/telegram/stats");
request.Headers.Add("x-api-key", "YOUR_API_KEY");
request.Headers.Add("x-account-id", "YOUR_ACCOUNT_ID");
var content = new StringContent("{\"type\":\"DAILY\",\"start_time\":\"2024-01-01T00:00:00.000Z\",\"end_time\":\"2024-01-31T23:59:59.000Z\",\"timezone\":\"UTC\"}", null, "application/json");
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
Understanding the Response
The endpoint returns an array of stat objects, one entry per time interval within the requested range.
JSON Schema:
[
{
"total_requests": 842,
"total_transactions": 809,
"total_amount": 8.09,
"currency": "EUR"
},
{
"total_requests": 731,
"total_transactions": 714,
"total_amount": 7.14,
"currency": "EUR"
}
]
| Field | Type | Description |
|---|---|---|
| total_requests | number | Total number of OTP messages requested in the interval. |
| total_transactions | number | Number of messages that were successfully processed. |
| total_amount | number | Total billing amount for the interval. |
| currency | string | Currency of the reported amounts (default: "EUR"). |
Error Handling
- 400 - Bad Request: Invalid stat type, missing fields, or malformed time range
- 401 - Unauthorized: Authentication failed
- 500 - Internal Server Error: An unexpected error occurred on the server