Skip to main content
Question

Sending a fax does not work when you have attachments

  • February 8, 2022
  • 2 replies
  • 371 views

I have the following problem:

I am using the code for sending a fax as it is published in the official documentation.


// Send Fax

$request = $rcsdk->createMultipartBuilder()
                 ->setBody(array(
                     'to'         => array(
                         array('phoneNumber' => xxxxxxxxxxxxx),
                     ),
                     'faxResolution' => 'High',
                 ))
                 ->add('Plain Text', 'file.txt')
                 ->add(fopen('https://developers.ringcentral.com/assets/images/ico_case_crm.png', 'r'))
                 ->request('/account/~/extension/~/fax');

//print $request->getBody() . PHP_EOL;

$response = $platform->sendRequest($request);

print 'Sent Fax ' . $response->json()->uri . PHP_EOL;


This works perfectly for me in my local development environment. (Windows 10, WampServer, php 7.2.25, Laravel 5.5.9). But when I do the deploy in LIVE (aws, ngix, php 7.2.25, Laravel 5.5.9) it doesn't send the fax and it gives me the following error:

ERROR: 400 Bad Request (and additional error happened during JSON parse: Response is not JSON) {"userId":00,"email":"xxxxxx@xxx.com","exception":"[object] (RingCentralSDKHttpApiException(code: 400): 400 Bad Request (and additional error happened during JSON parse: Response is not JSON) at /home/forge/onemed.us/vendor/ringcentral/ringcentral-php/src/Http/Client.php:52, Exception(code: 0): Response has unsuccessful status at /vendor/ringcentral/ringcentral-php/src/Http/Client.php:44)
[stacktrace]
#0 vendor/ringcentral/ringcentral-php/src/Platform/Platform.php(310): RingCentralSDKHttpClient->send(Object(GuzzleHttpPsr7Request))
#1 app/Http/Controllers/RingCentralController.php(353): RingCentralSDKPlatformPlatform->sendRequest(Object(GuzzleHttpPsr7Request))


This occurs when there are files attached to the fax. When there is none, the fax is sent

I have read in other threads that there are users with some similar problems but they do not detail the solution.



2 replies

  • 0 replies
  • February 8, 2022

It could be that the headers Content-Type for Send Fax might be wrong . The content-type is supposed to be 'multipart/mixed'

Can you change your code to something like this ?


@Yatin Gera @Yatin Gera Can you please test the PHP SDK and make changes as necessary ?

 $builder = new MultipartBuilder();
 $builder->setBody(['to' => ['phoneNumber' => 'foo'], 'faxResolution' => 'High'])
                ->setBoundary('boundary')
                ->add('plain text', 'plain.txt', ['Content-Type' => 'text/custom']);

  • 0 replies
  • February 10, 2022

@Ivan Irias
What you seem to be missing is adding a form boundary to be used in the multipart form request
The SDK will take care of creating the form data for you with multiple attachments but you need to provide a form data boundary


<?php
require('vendor/autoload.php');


$RECIPIENT = '<NUMBER>';
$RINGCENTRAL_CLIENTID = '<CLIENT_ID>';
$RINGCENTRAL_CLIENTSECRET = '<CLIENT_SECRET>';
$RINGCENTRAL_SERVER = RingCentralSDKSDK::SERVER_PRODUCTION;


$RINGCENTRAL_USERNAME = '<USERNAME>';
$RINGCENTRAL_PASSWORD = '<PASSWORD>';
$RINGCENTRAL_EXTENSION = '';


$rcsdk = new RingCentralSDKSDK($RINGCENTRAL_CLIENTID, $RINGCENTRAL_CLIENTSECRET, $RINGCENTRAL_SERVER);


$platform = $rcsdk->platform();
$platform->login($RINGCENTRAL_USERNAME, $RINGCENTRAL_EXTENSION, $RINGCENTRAL_PASSWORD);


$request = $rcsdk->createMultipartBuilder()
->setBody(array(
  'to' => array(array('phoneNumber' => $RECIPIENT)),
  'faxResolution' => 'High',
  'coverPageText' => 'Sending using PHP'
))
->setBoundary('--multipart-form-boundary--')
->add(fopen('https://developers.ringcentral.com/assets/images/ico_case_crm.png', 'r'))
->add('First page with text', 'first.txt')
->add('Second page with text', 'second.txt')
->add(fopen('https://developers.ringcentral.com/assets/images/ico_case_crm.png', 'r'))
->request('/account/~/extension/~/fax');


$resp = $platform->sendRequest($request);
print_r ("FAX sent. Message status: " . $resp->json()->messageStatus);
?>


This should be helpful

Let me know if you are still stuck.

Best,
Yatin


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings