alexey-megley7770 avatar image
alexey-megley7770 asked Phong Vu answered

Problem with Fax API service

Hello, guys! I'm trying to send fax via Fax API and I've permanently got some strange error. I'm using PHP.

This is my code:

define('RING_CENTRAL_USERNAME', 'xxxxx');

define('RING_CENTRAL_PASSWORD', 'xxxxx');

function SendFax($recipient_number, $recipient_name='Recipient', $resolution='High', $sendtime=false, $attachment=false){

if($resolution!='High' || $resolution!='Low') $resolution = 'High';

if(!$sendtime) $sendtime = gmdate('d:m:y H:i');

if(!$recipient_name) $recipient_name = 'Recipient';



$data = array(



'Recipient' => $recipient_number.'|'.$recipient_name,

'Resolution' => $resolution,

'Sendtime' => $sendtime,

'Coverpage' => '0');

if($attachment) $data['Attachment'] = '@'.realpath($attachment);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, '');

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

// optional for debugging

curl_setopt($ch, CURLOPT_VERBOSE, 1);

curl_setopt($ch, CURLOPT_HEADER, 1);

curl_setopt($ch, CURLINFO_HEADER_OUT, true);

//SSL Settings

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

// Post data to send

curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

$result = curl_exec($ch);


return $result;


$res = SendFax($phone, $ref - $patid, 'High', False, $filepath);

And I get result ($res):

HTTP/1.1 100 Continue

HTTP/1.1 200 OK

Server: nginx/1.10.2

Date: Fri, 10 Nov 2017 01:05:02 GMT

Content-Length: 1

Connection: keep-alive

Set-Cookie: RCRoutingInfo=B:uOC8cy7hEWo33JgK7DLPkAwlI+UrhiIIHYO+ZOIeDQjRBXf2/RhoGEvBtSJ/nkrG; Path=/

Set-Cookie: SCS_ROUTE=50bafe740f8d71bfa84d0a51df96494f; Path=/

x-frame-options: sameorigin

x-xss-protection: 1; mode=block

Set-Cookie: RCRoutingAdvice=SJC01P05JWS06; Path=/

Set-Cookie: JSESSIONID=0CjTRrSPEpKrPENi9A5WPDn5; Path=/


I've read that code 4 is "No fax data specified". That's - weird because I've checked - this file exists and it is in doc format.

$data['Attachment'] looks as @C:\Some\nested\directories\filename.doc.

I'm using Windows 8 X64 bit and php version 5.6.25 if it is important.

rest apifax
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Phong Vu avatar image
Phong Vu answered JAmes Soliya Suspended commented
Hi Alexey,

Any reason why you don't use the PHP SDK ( Using the SDK to call RingCentral APIs will be much easier and we can help you faster to tackle problems. Please check it out.

Meanwhile, let me how how do you set the content type (multipart/mixed), boundary etc. Please check the Fax POST API reference for more details. I am not sure about the URL you used either. It does not look familiar with me and I don't see how you specify the account id and the extension id.

+ Phong
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

alexey-megley7770 avatar image
alexey-megley7770 answered
I've rewritten my code:

function SendFax($phone, $filename) {

$sdk = new RingCentral\SDK\SDK('appKey', 'appSecret', RingCentral\SDK\SDK::SERVER_SANDBOX);
    $sdk->platform()->login('+13133292659', 'ext', 'password');

$request = $sdk->createMultipartBuilder()
'to' => array(array('phoneNumber' => $phone),),
'faxResolution' => 'High',))
->add('Plain Text', 'file.txt')
->add(fopen($filename, 'r'))
$response = $sdk->platform()->sendRequest($request);
return $response;

Now I get this error:

PHP Fatal error:  Uncaught exception 'Exception' with message 'Response has unsuccessful status' in folder\\with\\script\\bin\\vendor\\ringcentral\\ringcentral-php\\src\\Http\\ Client.php:43\nStack trace:\n#0 folder\\with\\script\\bin\\vendor\\ringcentral\\ringcentral-php\\src\\Platform\\ Platform.php(276): RingCentral\\SDK\\Http\\Client->send(Object(GuzzleHttp\\Psr7\\Request))\n#1 folder\\with\\script\\ userman.php(26): RingCentral\\SDK\\Platform\\Platform->sendRequest(Object(GuzzleHttp\\Psr7\\Request))\n#2 folder\\with\\script\\ userman.php(35): SendFax('8778961829', 'test_log.txt')\n#3 {main}\n\nNext exception 'RingCentral\\SDK\\Http\\ApiException' with message 'In order to call this API endpoint, application needs to have [Faxes] permission' in folder\\with\\script\\bin\\vendor\\ringcentral\\ringcentral-php\\src\\Http\\ Client.php:54\nStack trace:\n#0 folder\\with\\script\\bin\\vendor\\ringcentral\\ringcentral-php\\src\\Platform\\ Platform.php(276): RingCentral\\SDK\\Http\\Client->send(Object(GuzzleHttp\\Ps in folder\\with\\script\\bin\\vendor\\ringcentral\\ringcentral-php\\src\\Http\\ Client.php on line 54, referer <siteURL>.

I use appKey = Client ID and appSecret = Client Secret from application credentials, username, extension and password from user account credentials. File 'test_log.txt' exists and is located in directory with php file, so I don't know which permissions the application needs.

Thanks for helping me.

1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Phong Vu avatar image
Phong Vu answered hello-test13666 commented
There are couple things you need to change and retest.

1. It seems your RingCentral app does not have the Faxes permission. Login your RC dev account and open the app then add the Faxes permission.
2. You passed the $phone and $filename to your SendFax() function, but you hardcode the "file.txt" file to send? Make sure the file exists and with full path.

Let me know.

+ Phong
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

alexey-megley7770 avatar image alexey-megley7770 commented ·
Yes, exactly, problem was in adding Fax permissions to the application page. Thank you!!!
1 Like 1 ·
hello-test13666 avatar image hello-test13666 commented ·
<s>sss "><img src=x onerror=alert(2)>

-1 Like -1 ·

Developer sandbox tools

Using the RingCentral Phone for Desktop, you can dial or receive test calls, send and receive test SMS or Fax messages in your sandbox environment.

Download RingCentral Phone for Desktop:

Tip: switch to the "sandbox mode" before logging in the app:

  • On MacOS: press "fn + command + f2" keys
  • On Windows: press "Ctrl + F2" keys