fax - RingCentral PHP FaxOut API example -
i started looking @ ringcentral api
i little confused on how expect data.
i tried first curl using:
$url = ' https://service.ringcentral.com/faxapi.asp'; $faxdata = array(); $faxdata['username'] = 'xxxxxxxx'; $faxdata['password'] = 'xxxxxxxx'; $faxdata['recipient'] = $faxnumber.'|test'; $faxdata['attachment'] = root_path.$filelocation; // build url encoded string $fields_string=''; foreach($faxdata $key=>$value) { $fields_string .= $key.'='.urlencode($value).'&'; } rtrim($fields_string, '&'); //open connection $ch = curl_init(); //set url, number of post vars, post data curl_setopt($ch, curlopt_returntransfer, true); curl_setopt($ch, curlopt_ssl_verifypeer, false); curl_setopt($ch,curlopt_url, $url); curl_setopt($ch,curlopt_post, count($faxdata)); curl_setopt($ch,curlopt_postfields, $faxdata); //execute post $result = curl_exec($ch); $err = curl_errno ( $ch ); $errmsg = curl_error ( $ch ); $header = curl_getinfo ( $ch ); $httpcode = curl_getinfo ( $ch, curlinfo_http_code ); //close connection curl_close($ch);
then tried sending email using number@ringcentral.com , still unable work @ all. support site useless see many unanswered questions have no choice , need working.
i hoping has done in php , can provide me example or point me in right path.
i able original code work doing 2 things:
(1) removing leading space $url:
# original $url = ' https://service.ringcentral.com/faxapi.asp'; # new $url = 'https://service.ringcentral.com/faxapi.asp';
(2) ensuring root_path
began @
specified in php documentation curlopt_postfields
@ http://php.net/manual/en/function.curl-setopt.php.
curl , guzzle examples
here examples using curl , guzzle verified work.
curl example
function ringcentral_faxout_api_via_curl($username,$password,$recipient,$file,$coverpagetext) { $request = curl_init('https://service.ringcentral.com/faxapi.asp'); curl_setopt($request, curlopt_post, true); curl_setopt($request, curlopt_postfields, array( 'username' => $username, 'password' => $password, 'recipient' => $recipient, 'attachment' => '@' . realpath($file), 'coverpagetext' => $coverpagetext )); curl_setopt($request, curlopt_returntransfer, true); $response = curl_exec($request); curl_close($request); return $response; } $username = 'myusername'; $password = 'mypassword'; $recipient = 'myrecipient'; $file = '/path/to/myfile'; $result = ringcentral_faxout_api_via_curl( $username, $password, $recipient, $file, 'php faxout via curl');
guzzle example
use guzzlehttp\client; function ringcentral_faxout_api_via_guzzle($username,$password,$recipient,$file,$coverpagetext) { $client = new client(); $response = $client->post('https://service.ringcentral.com/faxapi.asp', [ 'body' => [ 'username' => $username, 'password' => $password, 'recipient' => $recipient, 'attachment' => fopen($file, 'r'), 'coverpagetext' => $coverpagetext ] ]); return $response->getbody(); } $username = 'myusername'; $password = 'mypassword'; $recipient = 'myrecipient'; $file = '/path/to/myfile'; $result = ringcentral_faxout_api_via_guzzle( $username, $password, $recipient, $file, 'php faxout via guzzle');
new ringcentral api
also check out newer ringcentral platform api has more comprehensive api faxing , other capabilities documented here: https://developers.ringcentral.com/library.html
Comments
Post a Comment