News & Announcements User Community Developer Community

Welcome to the RingCentral Community

Please note the community is currently under maintenance and is read-only.

Make sure to review our Terms of Use and Community Guidelines.
  Please note the community is currently under maintenance and is read-only.
Home » Developers
Sending a fax does not work when you have attachments
Tags: fax
Feb 8, 2022 at 11:28am   •   2 replies  •  0 likes
Ivan Irias

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()
                     'to'         => array(
                         array('phoneNumber' => xxxxxxxxxxxxx),
                     'faxResolution' => 'High',
                 ->add('Plain Text', 'file.txt')
                 ->add(fopen('', 'r'))

//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":"","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/, Exception(code: 0): Response has unsuccessful status at /vendor/ringcentral/ringcentral-php/src/Http/Client.php:44)
#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.

2 Answers
answered on Feb 10, 2022 at 12:07am  

@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





$platform = $rcsdk->platform();

$request = $rcsdk->createMultipartBuilder()
  'to' => array(array('phoneNumber' => $RECIPIENT)),
  'faxResolution' => 'High',
  'coverPageText' => 'Sending using PHP'
->add(fopen('', 'r'))
->add('First page with text', 'first.txt')
->add('Second page with text', 'second.txt')
->add(fopen('', 'r'))

$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.


answered on Feb 8, 2022 at 2:23pm  

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'])
                ->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

Developer Platform
Integrated Apps
App Gallery
Developer support
Games and rewards

Resource center
Product Releases
App Download
RingCentral App login
Admin Portal Login
Contact Sales
© 1999-2024 RingCentral, Inc. All rights reserved. Legal Privacy Notice Site Map Contact Us