API - Reports¶
Reports API is used to extract the data of a report from the PBX (a standard report or a custom report defined in Reports).
API URL¶
https://[YOUR-PBX-URL]/api/reports
Data is sent via POST or GET and must be of the form:¶
Array
(
[page] => 1
[data] => Array
(
[type] => custom
[id] => 2
)
[filters] => Array
(
[date_between] => Array
(
[0] => 2024-01-01 00:00:00
[1] => 2024-01-15 23:59:59
)
)
[api_hash] => 07112231a9c89f5b108af08608a97b07
)
The data parameter is mandatory and contains:
- type: custom (report saved in Reports, must be active) or standard (predefined report)
- id: the report ID, numeric for custom, text for standard (eg: cdr_api - list of calls with all the details)
The columns in results are the ones defined in the report. For a custom report associated with a project, only the data of that project is returned.
The page parameter defaults to 1 and is incremented up to pagination.max_page (a page greater than max_page still returns the last page). Rows are returned 100 per page.
HTTP Headers:¶
Content-Type: application/json Authorization: Bearer <token>
Filters:¶
- date_between: array(from, to). Format: Y-m-d H:i:s (eg: 2024-01-01 00:00:00). For custom reports it is applied on the date column chosen in the report
The other report filters can also be sent; for call reports (eg: cdr_api) they are the same as in API CDR (eg: project_ids, direction, telephone, queue, from_id - calls with an ID greater than or equal, useful for incremental synchronization).
Example of parameters generation:
$params = array(
'page' => 1,
'data' => array(
'type' => 'custom', // standard
'id' => 2 // cdr_api
),
'filters' => array(
'date_between' => array('2024-01-01 00:00:00', '2024-01-15 23:59:59'), // array(from, to)
)
);
Example of hash generation:
$params['api_hash'] = md5(json_encode($params) . 'your_api_key'); // make hash
Example of sending data:
$url = 'https://[YOUR-PBX-URL]/api/reports';
$token = 'your_api_token';
echo curlPost($url, json_encode($params), array("Authorization: Bearer {$token}", "Content-Type: application/json"));
Data sent JSON¶
{
"page": 1,
"data": {
"type": "custom",
"id": 2
},
"filters": {
"date_between": [
"2024-01-01 00:00:00",
"2024-01-15 23:59:59"
]
},
"api_hash": "af4014d3db711e82cdcc74bb8c64fdc4"
}
Response¶
If successful:
{
"has_error": false,
"messages": [ ],
"pagination": {
"row_count": 1,
"page_size": 100,
"current_page": 1,
"max_page": 1
},
"results": [
{
"id": "29056",
"uniqueid": "1710401324.480",
"linkedid": "1710401324.480",
"time": "2024-03-14 09:28:44",
"time_end": "2024-03-14 09:31:02",
"caller_id": "0712345678",
"source": "0712345678",
"destination": "0212345000",
"direction": "IN",
"user_username": "john-doe",
"queue": "sales-queue",
"call_status": "ANSWERED",
"project": "Test project"
}
]
}
Or in case of error (Request data array is missing, Request data ID is missing / invalid, Request data Type is missing / invalid, Invalid report ID: ...):
{
"has_error": true,
"messages": [
"Invalid report ID: 999"
],
"pagination": [ ],
"results": [ ]
}
Available in other languages: RO