WAPI – example in PHP

The following script requires the extension curl. Variables $login a $wpass substitute by login to your customer account and password to WAPI interface (a password that you have set in the WAPI settings it is not a customer account password).

// parameters of XML request
$login = 'tester';
$wpass = 'fdsaasdf';
$auth = sha1($login.sha1($wpass).date('H', time()));
$command = 'ping';
$cltrid = 'test_req_1';

// compilation of XML
$request = '<?xml version="1.0" encoding="UTF-8"?>
<request>
 <user>'.$login.'</user>
 <auth>'.$auth.'</auth>
 <command>'.$command.'</command>
 <clTRID>'.$cltrid.'</clTRID>
</request>';

// address
$url = 'https://api.wedos.com/wapi/xml';

// POST data
$post = 'request='.urlencode($request);

// initialization cURL session
$ch = curl_init();

// setting URL and data POST 
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$post);

// response we want as a return value curl_exec()
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);

// timeout which the script waits for a response
curl_setopt($ch,CURLOPT_TIMEOUT,100);

// execution
$res = curl_exec($ch);

// listing results on output
echo '<pre>'.htmlspecialchars(print_r($res, true)).'</pre>';
Děkujeme za zpětnou vazbu!