API - Call Detail Records - CDR Save¶
CDR API is used to save information about calls in the PBX
API URL¶
https://[YOUR-PBX-URL]/api/cdr
Data is sent via POST or GET and must be of the form:¶
Array
(
[action] => save
[data] => Array
(
[0] => Array
(
[id] => 35097
[comments] => test comment
[accounting_code] => test code 1234
[transcriptions] => Array
(
[0] => Array
(
[type] => monitor
[filename] => 1749628794.686
[provider] => stt_provider
[remote_id] => recording_12345
[text] => Sample transcription text
[metadata] => Array
(
[test_string1] => Good
[another_string2] => Bad
[test_score] => 1
[another_score] => 4
)
)
)
)
)
[api_hash] => 07112231a9c89f5b108af08608a97b07
)
Parameters:¶
- action: must have the value save
- data: list of calls to update; each row contains:
- id: the call ID (the id field from API - CDR, not uniqueid), mandatory
- comments: comment, optional; an empty text deletes the comment
- accounting_code: accounting code, optional, maximum 100 characters; an empty text deletes it
- transcriptions: list of transcriptions, optional; for each one:
- type: the file type: monitor, recording or confbridge, mandatory
- filename: the name of the transcribed file, mandatory
- provider: the transcription provider, mandatory
- remote_id: the transcription ID at the provider, mandatory
- text and / or metadata (object): at least one is mandatory
If a transcription with the same remote_id and provider already exists for the call, it is updated.
Each row in data is processed separately: valid rows are saved even if others have errors (has_error = true). The errors of a row are keyed by the row index in data; transcription errors have the key transcriptions::<row index>::<transcription index> (eg: transcriptions::1::0), one for each invalid transcription. Invalid transcriptions are ignored, the valid ones in the same row are saved. Results are keyed by the call ID. call_updated is the number of modified rows (0 if the values were already the same) and appears only if comments or accounting_code was sent; transcriptions_ids contains the IDs of the saved transcriptions.
Example of parameters generation:
$params = [
'action' => 'save',
'data' => [
[
'id' => 35097,
'comments' => 'test comment', // optional
'accounting_code' => 'test code 1234', // optional
'transcriptions' => [
[
'type' => 'monitor', // 'monitor','recording','confbridge'
'filename' => '1749628794.686', // required
'provider' => 'stt_provider', // required
'remote_id' => 'recording_12345', // required
'text' => 'Sample transcription text',
'metadata' => [
'test_string1' => 'Good',
'another_string2' => 'Bad',
'test_score' => 1,
'another_score' => 4
]
]
]
]
]
];
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/cdr';
$token = 'your_api_token';
echo curlPost($url, json_encode($params), array("Authorization: Bearer {$token}", "Content-Type: application/json"));
Data sent JSON¶
{
"action": "save",
"data": [
{
"id": 35097,
"comments": "test comment",
"accounting_code": "test code 1234",
"transcriptions": [
{
"type": "monitor",
"filename": "1749628794.686",
"provider": "stt_provider",
"remote_id": "recording_12345",
"text": "Sample transcription text",
"metadata": {
"test_string1": "Good",
"another_string2": "Bad",
"test_score": 1,
"another_score": 4
}
}
]
}
],
"api_hash": "7645211b387997bd96a8b77f03f6aa91"
}
Response¶
If successful:
{
"has_error": false,
"messages": [],
"results": {
"35097": {
"call_updated": 0,
"transcriptions_ids": [
44
]
}
}
}
Or in case of error:
{
"has_error": true,
"messages": {
"0": "Required parameter is missing from data array: id",
"transcriptions::1::0": "Invalid transcription data [0] for call ID 35098",
"transcriptions::1::2": "Invalid transcription data [2] for call ID 35098"
},
"results": {
"35098": {
"transcriptions_ids": [
512
]
}
}
}
Available in other languages: RO