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] (RingCentral\\SDK\\Http\\ApiException(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): RingCentral\\SDK\\Http\\Client->send(Object(GuzzleHttp\\Psr7\\Request)) #1 app/Http/Controllers/RingCentralController.php(353): RingCentral\\SDK\\Platform\\Platform->sendRequest(Object(GuzzleHttp\\Psr7\\Request))
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.
@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 = RingCentral\SDK\SDK::SERVER_PRODUCTION; $RINGCENTRAL_USERNAME = '<USERNAME>'; $RINGCENTRAL_PASSWORD = '<PASSWORD>'; $RINGCENTRAL_EXTENSION = ''; $rcsdk = new RingCentral\SDK\SDK($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
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']);
A new Community is coming to RingCentral!
Posts are currently read-only as we transition into our new platform.We thank you for your patience
during this downtime.
Try Workflow Builder
Did you know you can easily automate tasks like responding to SMS, team messages, and more? Plus it's included with RingCentral Video and RingEX plans!Try RingCentral Workflow Builder