News & Announcements User Community Developer Community

Welcome to the RingCentral Community

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

Search
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
Issue Trying to send a fax using fax sdk php
Tags: fax
Nov 17, 2023 at 9:07am   •   1 replies  •  0 likes
Chris Karagiannis
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...)
1 Answer
answered on Nov 17, 2023 at 10:50am  

Thanks for responding Phong. 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?


 0
answered on Nov 17, 2023 at 10:22am  

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);

 0
on Nov 17, 2023 at 10:59am   •  0 likes

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.



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

PRODUCTS
RingEX
Message
Video
Phone
OPEN ECOSYSTEM
Developer Platform
APIs
Integrated Apps
App Gallery
Developer support
Games and rewards

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