PHP 5.2 Curl Fax Code Examples

  • 1
  • Question
  • Updated 3 months ago
  • Answered
So unfortunately I'm stuck on PHP 5.2.3 and cannot upgrade, thus cannot use the official PHP SDK. I need examples of how to set up the FaxOut after obtaining a valid Access Token. Been stuck for the past 3 days.
Photo of Drew Bolton

Drew Bolton

  • 130 Points 100 badge 2x thumb

Posted 3 months ago

  • 1
Photo of Tyler Long

Tyler Long, Official Rep

  • 6,918 Points 5k badge 2x thumb
I can show you how to do it with curl. You try to adjust it for PHP curl. 

curl \
--header "Accept: application/json" \
--header "Authorization: Bearer <token>" \
-F "request=@request.json;type=application/json" \
-F "attachment=@hello.txt;type=text/plain" \
"https://platform.devtest.ringcentral.com/restapi/v1.0/account/~/extension/~/fax";


Content of request.json file:
{
"to": [{ "phoneNumber": <fax receiver> }]
}


Content of hello.txt:
<Whatever text you want to send.>


You can also send pdf:
-F "attachment=@test.pdf;type=application/pdf"
Photo of Tyler Long

Tyler Long, Official Rep

  • 6,918 Points 5k badge 2x thumb
Been stuck for the past 3 days.
You should have asked for help earlier :)
Photo of Drew Bolton

Drew Bolton

  • 130 Points 100 badge 2x thumb
But how do I translate that to PHP cURL lib?... such as using curl_init(), curl-setopt(), etc?

Ya, 1.5 days were stuck reading docs and the other 1.5 days were trying to implement things fruitlessly. 
Photo of John Wang

John Wang, Official Rep

  • 5,476 Points 5k badge 2x thumb
Drew,

Try out my PHP "Lite" SDK. It's a 1-file, 0-dependency library designed to support older PHP and uses cURL.

You can see a fax example using the SDK here:

https://github.com/grokify/ringcentral-sdk-php-lite#send-a-fax

You can see the SDK's cURL code here:

https://github.com/grokify/ringcentral-sdk-php-lite/blob/master/src/ringcentrallite.php#L139

I don't have PHP 5.2.3, so let me know if it works for you.
(Edited)
Photo of Drew Bolton

Drew Bolton

  • 130 Points 100 badge 2x thumb
Ah, this looks nice! I'll get this a shot and see if I can get this to work with my set up. I'll let you know how it goes.
Photo of John Wang

John Wang, Official Rep

  • 5,476 Points 5k badge 2x thumb
If you have any suggestions please feel free to post here or create a GitHub issue or pull request. I'm interested in improving this as needed.
Photo of Drew Bolton

Drew Bolton

  • 130 Points 100 badge 2x thumb
Ok, so how do I do multiple attachments? I tried passing in an array into 'attachment' of the param, but throws error. Any thoughts, suggestions? I need to fax multiple documents at one time.
Photo of John Wang

John Wang, Official Rep

  • 5,476 Points 5k badge 2x thumb
PHP cURL does not seem to have the ability to post multiple files with the same name as other solutions can. The cURL CLI app and other solutions like Faraday in Ruby can do this.

The best solution using PHP cURL seems to be to manually build a multipart/form-data post. Let me know if you can get this to work. I'll look into this but it might be a while before I can get to it.

https://stackoverflow.com/questions/871431/raw-post-using-curl-in-php
(Edited)
Photo of Tyler Long

Tyler Long, Official Rep

  • 6,878 Points 5k badge 2x thumb
Another solution is to invoke the command line curl to get the job done: https://stackoverflow.com/questions/6796617/execute-command-line-via-php

Here is an article about cURL for RingCentral API: https://medium.com/@tylerlong/use-curl-to-access-ringcentral-platform-api-d4710fe68fa4
Photo of Tyler Long

Tyler Long, Official Rep

  • 6,918 Points 5k badge 2x thumb
Curl to PHP: https://incarnate.github.io/curl-to-php/

Update: I find that  it doesn't support '-F' at all, so ignore this one.
(Edited)
Photo of Drew Bolton

Drew Bolton

  • 130 Points 100 badge 2x thumb
Thanks Tyler, I actually figured out how to translate it myself shortly after asking. Gonna see if John's sdk lite works for me, otherwise I'll roll my own and let you guys know how it does.