PHP PDF Fax Syntax

  • 1
  • Question
  • Updated 1 week ago
What is the proper syntax to send a PDF via the PHP SDK?  I tried the demo code and was able to successfully send a fax.  Now I am trying to send a PDF that exists in the root directory of the app and getting RenderingFailed messages.  Here is my code:

$request = $rcsdk->createMultipartBuilder()
->setBody(array(
'to' => array( array('phoneNumber' => $phone), ), 'faxResolution' => 'High', )) ->add('','attachment1.pdf') ->request('/account/~/extension/~/fax'); $response = $rcsdk->platform()->sendRequest($request); I have also tried with these and received without success ...
->add('pdf','attachment1.pdf')
->add('application/pdf','attachment1.pdf')
The ->add line is the only difference between the demo code and the live code.
Photo of FIELDS RESEARCH, INC.

FIELDS RESEARCH, INC.

  • 200 Points 100 badge 2x thumb
  • frustrated

Posted 1 week ago

  • 1
Photo of Phong Vu

Phong Vu, Devangelist

  • 3,252 Points 3k badge 2x thumb
Basically if your app works on sandbox environment, it should work on production as well. Can you double check the location of the attachment, and by any chance you forgot to change the Client ID/Secret for production in your app?

If these all correct, can you post the entire response and let me know so I can try to replicate the problem.

+ Phong
Here is the response after initiating send fax:

stdClass Object
(
    [uri] => https://platform.devtest.ringcentral.com/restapi/v1.0/account/~/extension/251167004/message-store/~
    [id] => 566925****
[to] => Array ( [0] => stdClass Object ( [phoneNumber] => ***** [location] => ***** [messageStatus] => Queued ) ) [type] => Fax [creationTime] => 2018-12-03T20:17:52.000Z [readStatus] => Unread [priority] => Normal [attachments] => Array ( [0] => stdClass Object ( [id] => 566925**** [uri] => https://media.devtest.ringcentral.com/restapi/v1.0/account/251167004/extension/251167004/message-store/5669254004/content/5669254004 [type] => RenderedDocument [contentType] => application/pdf ) ) [direction] => Outbound [availability] => Alive [messageStatus] => Queued [faxResolution] => High [faxPageCount] => 0 [lastModifiedTime] => 2018-12-03T20:17:52.792Z [coverIndex] => 7
)
After a few minutes "messageStatus" is updated to  "SendingFailed"  and "faxErrorCode" is updated to  "RenderingFailed".    

I am using the sandbox credentials to test this.  \

Please confirm this syntax correct:

->add('pdf',[full path to pdf])

If not, what should it be?  The documentation does not specify what the two variables are in the ->add event.





Photo of Tyler Long

Tyler Long, Official Rep

  • 8,492 Points 5k badge 2x thumb
RenderFailed probably means that PDF file is invalid. Could you please try with another pdf file?
I tried it with a different PDF and received the same error.  
It was a syntax issue...

 ->add('Plain Text', 'file.txt') is to be used when you want to create a file and fax.

->add(fopen('[full path to file]', 'r')) is to be used to add an existing file to the fax.

I was able to send both faxes using the fopen method.

Thanks!
Photo of Tyler Long

Tyler Long, Official Rep

  • 8,492 Points 5k badge 2x thumb
Great!