PHP code example of zadarma / user-api-v1

1. Go to this page and download the library: Download zadarma/user-api-v1 library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

zadarma / user-api-v1 example snippets



= new \Zadarma_API\Api(KEY, SECRET, USE_SANDBOX);
try{
    $result = $api->getSipStatus('YOURSIP');
    echo $result->sip.' status: '.($result->is_online ? 'online' : 'offline');
} catch (\Zadarma_API\ApiException $e) {
    echo 'Error: '.$e->getMessage();
}




ms = array(
    'id' => 'YOURSIP',
    'status' => 'on'
);

$zd = new \Zadarma_API\Client(YOUR_KEY, YOUR_SECRET);
/*
$zd->call('METHOD', 'PARAMS_ARRAY', 'REQUEST_TYPE', 'FORMAT', 'IS_AUTH');
where:
- METHOD - a method API, started from /v1/ and ended by '/';
- PARAMS_ARRAY - an array of parameters to a method;
- REQUEST_TYPE: GET (default), POST, PUT, DELETE;
- FORMAT: json (default), xml;
- IS_AUTH: true (default), false - is method under authentication or not.
*/
$answer = $zd->call('/v1/sip/redirection/', $params, 'put');

$answerObject = json_decode($answer);

if ($answerObject->status == 'success') {
    echo 'Redirection on your SIP "' . $answerObject->sip . " has been changed to " . $answerObject->current_status . ".";
} else {
    $answerObject->message;
}