Here are some API examples in PHP of how to apply parts of the PBX API when coding in PHP. The PBX API provides a HTTP-based interface to the Axeos PBX. It allows e.g. monitoring PBX users and VoIP phones state, originating calls, and retrieving call statistics. You can use the API to create e.g. your own custom wall boards, smartphone apps, or to connect your own business software.
The originate_call function
For more information on originating calls, please also read the API docs in this knowledge base. The documentation allows you to integrate many features into your own software or into third-party applications.
<!--?php <br ?-->/**************************************************************************************************************************** $url (string, required) – PBX server url + apis/pbx/call, e.g. https://my-pbx-server-url.com/apis/pbx/call $username (string, required) – PBX username $password (string, required) – PBX password $number (string, required) – number to dial (only numbers and the plus sign at the beginning and length < 20 if called like in the example below) $auto_answer (boolean, optional, default: false) - enable/disable the auto_answer option *********************** Response: * status (always): 'success', 'busy', 'no answer' or 'failed' * unique_id (only if status == 'success'): current call unique id (required e.g. to hang up a call) ****************************************************************************************************************************/ function originate_call($url, $username, $password, $number, $auto_answer = false) { $data = array('user_name' => $username, 'number' => $number, 'auto_answer' => $auto_answer); $auth = $username . ":" . $password; $options = array( 'http' => array( 'header' => "Content-type: application/x-www-form-urlencoded\r\n". "Authorization: Basic " . base64_encode($auth), 'method' => 'POST', 'content' => http_build_query($data), ) ); $context = stream_context_create($options); $result = file_get_contents($url, false, $context); if ($result === FALSE) { /* Handle error */ } var_dump($result); // for testing purposes, remove from the production code } ?>
Example ‘function call’
<!--?php $number = str_replace(<span class="code-quote">' '</span>, '', $number); <span class="code-keyword">if</span>(preg_match(<span class="code-quote">'/^+?\d+$/'</span>, $number) && strlen($number) < 20) { originate_call($url, $username, $password, $number, $auto_answer); } ?-->