question

Chris Karagiannis avatar image
Chris Karagiannis asked Chris Karagiannis edited

Issue Trying to send a fax using fax sdk php

Here is the code that I am trying to use and it fails, the pdf part is already done and stored in $pdfContent but I am unable to send the fax using Ring Central api/sdk call, it errors out.


// Generate the PDF content in memory
$pdfContent = $pdf->Output('S'); // 'S' stands for 'return as string'

$platform = $rcsdk->platform();
$platform->login( [ "jwt" => $JWT_TOKEN ] );

$dynamicFilename = 'attachment_' . time() . '.pdf';
$multipartBuilder = $rcsdk->createMultipartBuilder();

// Base64 encode the PDF content
$base64EncodedPdf = base64_encode($pdfContent);

$multipartBuilder->setBody(array(
'to' => array(array('phoneNumber' => $RECIPIENT)),
'faxResolution' => 'High',
));
      
// Add the PDF as an attachment
$multipartBuilder->add($base64EncodedPdf, 'application/pdf', array($dynamicFilename));

$headers = ['Content-Type' => 'multipart/mixed'];

$response = $platform->post('/restapi/v1.0/account/~/extension/~/fax', $multipartBuilder->body(), $headers);

but i get the error when i submit the form that makes the in-memory created pdf file (see below) but the faxResolution is set correctly according to the docs. Just a bit confused on this and even if this is possible to do what I am attempting to do. It seems straightforward but I am constantly getting errors. I was able to make the ring-out api work calling but now I want to add this using fax.


PHP Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: `POST https://platform.devtest.ringcentral.com/restapi/v1.0/account/~/extension/~/fax?Content-Type=multipart%2Fmixed` resulted in a `400 Bad Request` response:
{
"errorCode" : "InvalidParameter",
"message" : "Parameter [faxResolution] value is invalid.",
"errors" : [ {
(truncated...)
fax
1 |3000

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

1 Answer

Phong Vu avatar image
Phong Vu answered Chris Karagiannis edited

Unfortunately, the fax API does not support base64 encoded (the sample code in the API reference is incorrect). This is the only way how you fax attachments.

...
$request = $rcsdk->createMultipartBuilder()
                 ->setBody(array(
                     'to' => array(array('phoneNumber' => $RECIPIENT)),
                     'faxResolution' => 'High',
                 ))
                 ->add(fopen('log.txt', 'r'))
                 ->add(fopen('test.html', 'r'))
                 ->add(fopen('test.jpg', 'r'))
                 ->add(fopen('test.pdf', 'r'))
                 ->request('/account/~/extension/~/fax');

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

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

Chris Karagiannis avatar image Chris Karagiannis commented ·

Thanks for responding @Phong Vu . Just curious then in the scenario I described, would I then have to just cache the pdf file on the server in a file, then fopen that file and send the fax with the attached pdf file with the code you sent me. That's really the only way then? Or is there any other way to do what Im trying to do.

0 Likes 0 ·

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