How to get token with PHP code for P-Series API interface

  • Scenarios

To verify how to get token for Yeastar P-Series PBX API interface, users are possible to do it by the known tool named postman software which provides web UI interface.

For programmers they have to achieve it by code level, here we share demo code on how to get token with PHP language, please kindly note you have to replace variables $token_url and $login_data accordingly.

For appliance devices, PBXdomainOrIPaddress = IPaddress:8088, considering web port not changed.

For cloud instance, PBXdomainOrIPaddress = cloud domain name.

<?php
error_reporting(null);

$token_url = 'https://PBXdomainOrIPaddress/openapi/v1.0/get_token';
$user_agent = 'Mozilla/5.0 (Windows NT 10.0; WOW64)';
$login_data = '{
"username": "CheckItInYourPBX",
"password": "CheckItInYourPBX"
}';

$curl = curl_init($token_url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_USERAGENT, $user_agent);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER,array("Content-type: application/json"));
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $login_data);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);

$json_response = curl_exec($curl);
curl_close($curl);
print_r($json_response);

?>

 

  • Results

If everything is prepared well and php code is running properly, you should get succcessful API response like attached result.

{
"errcode":0,
"errmsg":"SUCCESS",
"access_token_expire_time":1800,
"access_token":"C0lqn9R18lDcgcBdRPp3Al00rPyeXHiF",
"refresh_token_expire_time":86400,
"refresh_token":"mHUwNQ51WfQIZUcSSHySzaym8CVD9swH"
}
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.