Tracking Call Detail Records

Humbug uses your Call Detail Records (CDR) as a primary means to analyze your telecom traffic, and requires all data to be sent using standard HTTP-POST using the below parameters.

CDR Event

URL to post data: http://api.humbuglabs.org/receiver.php
Parameter Type Description
gateway string Your API Key provided to your by Humbug
encoded int set to 1 if sending encoding data, 0 otherwise
Event string type of event. For sending CDR data, set this to: Cdr
Source string call originator in standard e.164 format. For example, a number in the UK would look like: 44207xxxxxxx
Destination string call termination in standard e.164 format. For example, a number in the UK would look like: 44207xxxxxxx
DestinationContext string Context of the call. You can set this to "inbound" or "outbound" to determine the behaviour of the call
CallerID string caller ID
Channel string originating channel, in the format of: Protocol/Trunk. For example, this might look like: SIP/att_inbound
DestinationChannel string terminating channel in the format of: Protocol/Trunk. For example, this might look like: SIP/att_outbound
StartTime DateTime start of the call; i.e. 2011-12-01 23:59:59
AnswerTime DateTime start of the call; i.e. 2011-12-01 23:59:59
EndTime DateTime end of the call; i.e. 2011-12-01 23:59:59
Duration int duration of the call in seconds
BillableSeconds int billable seconds
Disposition string disposition of the call. Some dispositions might be: ANSWERED, NO ANSWER, BUSY, FAILED, CANCEL, ERROR, CONGENSTION
UniqueID string custom unique ID of the call. This can be helpful for tracking data between your system and Humbug's records.
UserField string Set this to "inbound" or "outbound" to set behavior of the call
event_time DateTime Local time of your application/PBX

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

Sample Code

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);
								}