URL to post data: http://api.humbuglabs.org/receiver.php
Sample CDR POST Request:
gateway=YOUR_APIKEY&encoded=0&Event=Cdr&Source=15558624&Destination=155511044&DestinationContext=outbound&CallerID=15558624&Channel=SIP/trunk_name-000&DestinationChannel=SIP/trunk_name-0000&StartTime=2011-01-25 13:41:39&AnswerTime=2011-01-25 13:41:48&EndTime=2011-01-25 13:41:48&Duration=42&BillableSeconds=39&Disposition=ANSWERED&UniqueID=123456789.001&UserField=outbound&event_time=2011-01-25 13:41:48
PHP, unencoded data example
function send_humbug_data() {
//the url we are sending data to
$url = 'http://api.humbuglabs.org/receiver.php';
//in our example we're building an array of the values we need to send
$array = array (
'gateway' => 'your-api-key',
'encoded' => '0',
'Event' => 'Cdr',
'Source' => '15551234567',
'Destination' => '401',
'DestinationContext' => 'from-internal',
'CallerID' => '15551234567',
'Channel' => 'SIP/401@from-queue-aeff',
'DestinationChannel' => 'SIP/Trunk_out_01-0000000e',
'LastApplication' => 'Dial',
'LastData' => 'SIP/Trunk_out/15551234567,,trM(blkvm)',
'StartTime' => '2011-01-11 12:15:08',
'AnswerTime' => '2011-01-11 12:15:13',
'EndTime' => '2011-01-11 12:55:45',
'Duration' => '2437',
'BillableSeconds' => '2432',
'Disposition' => 'ANSWER',
'UniqueID' => '123456.123',
'UserField' => 'inbound',
'event_time' => date('Y-m-d h:i:s',time())
);
//turn the array into a key=value string for usage with cURL
$params = "";
foreach($array as $key => $value) {
$params .= $key.'='.$value.'&';
}
rtrim($params,'&');
//send the data
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($array));
curl_setopt($ch,CURLOPT_POSTFIELDS,$params);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
}
PHP, encoded data example
function send_encoded_humbug_data() {
//prepare the variables
$apikey = "your-api-key";
$key = "your-humbug-encryption-key";
$key_chars = str_split($key, 1);
$key_length = strlen ( $key );
//the url we are sending data to
$url = 'http://api.humbuglabs.org/receiver.php';
//in our example we're building an array of the values we need to send
$array = array (
'gateway' => $apikey,
'encoded' => '1',
'Event' => 'Cdr',
'Source' => '15551234567',
'Destination' => '401',
'DestinationContext' => 'from-internal',
'CallerID' => '15551234567',
'Channel' => 'SIP/401@from-queue-aeff',
'DestinationChannel' => 'SIP/Trunk_out_01-0000000e',
'LastApplication' => 'Dial',
'LastData' => 'SIP/Trunk_out/15551234567,,trM(blkvm)',
'StartTime' => '2011-01-11 12:15:08',
'AnswerTime' => '2011-01-11 12:15:13',
'EndTime' => '2011-01-11 12:55:45',
'Duration' => '2437',
'BillableSeconds' => '2432',
'Disposition' => 'ANSWER',
'UniqueID' => '123456.123',
'UserField' => 'inbound'
);
//turn the array into a key=value string for usage with cURL
$params = "";
foreach($array as $key => $value) {
$params .= $key.'='.$value.'&';
}
rtrim($params,'&');
//encode the data
$params_char = str_split($params, 1);
$str = "";
$i = 0;
foreach ( $params_char as $sym ) {
if ( $i == $key_length ) { $i = 0; }
$str .= sprintf ( '%02x', ord($sym ^ $key_chars[$i]));
$i++;
}
//build a new encoded request
$request = "gateway=".$apikey."&encoded=1&data=".$str;
//add an event_time
$request .="&event_time=".date('Y-m-d h:i:s',time());
//send the data
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,3);
curl_setopt($ch,CURLOPT_POSTFIELDS,$request);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
}
- When in doubt, leave required fields with "0" or blank, or contact us for help
