API - Call Detail Records - CDR Save¶
API CDR se foloseste pentru a salva informatii despre apeluri in centrala
API URL¶
https://[YOUR-PBX-URL]/api/cdr
Datele se transmit prin POST sau GET si trebuie sa fie de forma:¶
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
)
Parametri:¶
- action: trebuie sa aiba valoarea save
- data: lista de apeluri de actualizat; fiecare rand contine:
- id: ID-ul apelului (campul id din API - CDR, nu uniqueid), obligatoriu
- comments: comentariu, optional; un text gol sterge comentariul
- accounting_code: cod de contabilizare, optional, maxim 100 caractere; un text gol il sterge
- transcriptions: lista de transcrieri, optional; pentru fiecare:
- type: tipul fisierului: monitor, recording sau confbridge, obligatoriu
- filename: numele fisierului transcris, obligatoriu
- provider: furnizorul transcrierii, obligatoriu
- remote_id: ID-ul transcrierii la furnizor, obligatoriu
- text si / sau metadata (obiect): cel putin unul obligatoriu
Daca exista deja o transcriere cu acelasi remote_id si provider pentru apel, aceasta este actualizata.
Fiecare rand din data este procesat separat: randurile valide sunt salvate chiar daca altele au erori (has_error = true). Erorile unui rand au ca cheie indexul randului din data; erorile transcrierilor au cheia transcriptions::<index rand>::<index transcriere> (ex: transcriptions::1::0), cate una pentru fiecare transcriere invalida. Transcrierile invalide sunt ignorate, cele valide din acelasi rand sunt salvate. Rezultatele au ca cheie ID-ul apelului. call_updated este numarul de randuri modificate (0 daca valorile erau deja aceleasi) si apare doar daca s-a trimis comments sau accounting_code; transcriptions_ids contine ID-urile transcrierilor salvate.
Exemplu generare parametri:
$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
]
]
]
]
]
];
Exemplu generare hash:
$params['api_hash'] = md5(json_encode($params) . 'your_api_key'); // make hash
Exemplu trimitere date:
$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"));
Date trimise 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"
}
Raspuns¶
In caz de succes:
{
"has_error": false,
"messages": [],
"results": {
"35097": {
"call_updated": 0,
"transcriptions_ids": [
44
]
}
}
}
Sau in caz de eroare:
{
"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
]
}
}
}
Disponibil si in alte limbi: EN