Management of Api to download call history in UCM6208


#1

hello, I hope this is fine, my requirement is that I need to use the api of your commutator UCM6208, I have looked for examples and only found one, and it does not work when I make the request to the webservice send me an error 400 bad request, I am a programmer, so I need a routine to download the call records, save them in a database and be able to download the audios … I hope you can help me.

thank you.
Salvador R.


#2

You mean this is not enough ?


#3

Hi friend,
thank you for responding, I will be more explicit in my request … I need to automate the generation of these reports … by doing this:
https://192.168.18.253:8443/cdrapi?format=xml&startTime=2019-01-01T09:00: 00 & endTime = 2019-01-31T23: 59: 59
directly in any browser, there is no problem!!, but it has a routine specifically in PHP, the server does not allow to connect the look for a problem in the friend certificate. Look, this is the answer you give me …
Error --- SSL certificate problem: self signed certificate --- Outside url https://192.168.18.253:8443/cdrapi?format=xml&startTime=2019-01-01T09:00:00&endTime=2019-01-31T23:59: 59 Information curl_getinfo (Resource id # 4) string (9)

the problem is to make a request automatically … the code … is this:

> <?php
/*
 * Copyright by Petr Ivanov (petr.yrs@gmail.com)
 * 
 
 * Get CDR information from Grandstream UCM6202
 */
 $PBX = new Ucm6202('https://192.168.18.253', 'cdrapi', 'cdrapi123', '8443');
 $params = [
  'startTime' => '2019-01-01T09:00:00',
  'endTime' => '2019-01-31T23:59:59',
  
 ];
 /*'numRecords' => 10*/
 $data = $PBX->find($params);
 var_dump($data);
 
 
 /*Clase que hara el trabajo */

class Ucm6202 {
    /*
     * Host name or IP of PBX
     */
    private $host;
    /*
     * API port. Default 8443
     */
    private $port;
    /*
     * User name for access to API. Default 'cdrapi'
     */
    private $user;
    /*
     * User password for access to API. Default 'cdrapi123'
     */
    private $pass;
    /*
     * CURL handler
     */
    private $curl;
    /**
     * Initial connection to PBX API
     * @param string $host
     * @param string $user
     * @param string $pass
     * @param string $port 
     */
    public function __construct($host, $user = 'cdrapi', $pass = 'cdrapi123', $port = '8443') {
        $this->host = $host;
        $this->port = $port;
        $this->user = $user;
        $this->pass = $pass;
        $this->curl = curl_init();
		$cookie_jar = tempnam('/tmp','cookie');
		/*curl_setopt($this->curl, CURLOPT_CAINFO, dirname(__FILE__)."/cacert.pem");*/
		curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, 2);
        curl_setopt($this->curl, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($this->curl, CURLOPT_USERPWD, $this->user . ":" . $this->pass);
        curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($this->curl, CURLOPT_COOKIEJAR, $cookie_jar);
        curl_setopt($this->curl, CURLOPT_COOKIEFILE, $cookie_jar);
   curl_setopt($this->curl, CURLOPT_TIMEOUT, 50);			
    }
    /**
     * Find records from CDR
     * @param array $params
     * @return array|false
     */
    public function find($params = []) {
        $url = '/cdrapi?format=xml';
        $urlBuf = array_filter($params, function($item) {
            if (is_null($item)) {
                return false;
            } else {
                return true;
            }
        });
        $resBuf = [];
        foreach ($urlBuf as $key => $value) {
            $resBuf[] = $key . '=' . $value;
        }
        $urlParams = implode('&', $resBuf);
        if (strlen($urlParams) > 0) {
            $url .= '&' . $urlParams;
        }
        $url = $this->host . ':' . $this->port . $url;        
        curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($this->curl, CURLOPT_URL, $url);
        $result = curl_exec($this->curl);
		$httpcode = curl_getinfo($this->curl, CURLINFO_HTTP_CODE);
		$message = curl_error ($this->curl);
        echo "Error --- $message ---";
		echo "Fuera $result url $url Informacion curl_getinfo($this->curl) ";
        if ($result) {
            $res = CJSON::decode($result);
            $cdrRoot = $res['cdr_root'];
            $cdrRoot2 = [];
            foreach ($cdrRoot as $item) {
                if (!isset($item['start'])) {
                    if (isset($item['sub_cdr_3'])) {
                        $item['sub_cdr_3']['calldate'] = $item['sub_cdr_3']['start'];
                        $item['sub_cdr_3']['cdr_pkey'] = $item['sub_cdr_3']['AcctId'];
                        $cdrRoot2[] = $item['sub_cdr_3'];
                    } else {
                        continue;
                    }
                } else {
                    $item['calldate'] = $item['start'];
                    $item['cdr_pkey'] = $item['AcctId'];
                    $cdrRoot2[] = $item;
                }
            }
            return $cdrRoot2;
        } else {
            return "no entra ".FALSE;
        }
    }
}

/*END*/

This code belongs to: This code belongs to

This is the problem, I hope you can help me …
Regards, and thank you very much.!


#4

I’m not a programmer but this look bad:
" — Outside url "

I will not help much as i have no idea what to do. For me it look like server do not allow external connection, it maybe better to search help via GS ticket ?


#5

Well, it just says that I need a certificate, where could I get it?


#6

Just allow it, GS use self certificate.


#7

look at this is the problem…

Error — SSL certificate problem: self-signed certificate —

How do I allow it?


#8

There should be ADvanced or something in your browser, you will have there option to ignore this warning.