Premier IT Outsourcing and Support Services within the UK

User Tools

Site Tools


Asterisk provides a fully featured API via its REST interface allowing a range of functions to be performed programatically. Using PHP we will originate a call to a destination from a local extension. The local extension will ring, when answered the call will be made. This sort of functionality is probably the most common use of ARI to, for example originate a call from a CRM system or website.

$ariuser='username'; // The ARI Username as setup in Asterix
$aripass='password'; // The ARI Password as setup in Asterix
$asterisk=''; // The Asterix box IP Address and port number for ARI
$target='PJSIP/5000'; // The target (see below)
$destination='698'; // The destination (see below)
$callerid='1234'; // The CallerID to be presented
$context='from-internal'; // The context
$url = "http://".$ariuser.":".$aripass."@".$asterisk."/ari/channels"; 
$post=array('endpoint' => $target, 'extension' => $destination, 'context' => $context, 'priority' => '1', 'callerId' => $callerid);
$jpost = json_encode($post);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jpost); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($jpost),));  
$response = curl_exec($ch);

Target / Destination - This is the extension that will be called initially and when answered will then trigger a call to the destination.

DO NOT FORGET to comment/remove the print_r at the end when you've got it working.

/data/webs/external/dokuwiki/data/pages/php/using_asterisk_freepbx_elastix_to_make_a_call_from_php_via_ari_asterisk_rest_interface.txt · Last modified: 2019/07/12 14:05 by genadmin

Was this page helpful?-12+1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki