question

drew-bolton10590 avatar image
drew-bolton10590 asked Tyler Liu commented

PHP 5.2 Curl Fax Code Examples

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.

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.

Tyler Liu avatar image
Tyler Liu answered
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"

1 |3000

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

Tyler Liu avatar image
Tyler Liu answered
Been stuck for the past 3 days.
You should have asked for help earlier :)
1 |3000

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

drew-bolton10590 avatar image
drew-bolton10590 answered
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. 
1 |3000

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

John Wang avatar image
John Wang Deactivated answered Tyler Liu commented
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.
5 comments
1 |3000

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

drew-bolton10590 avatar image drew-bolton10590 commented ·
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.
1 Like 1 ·
John Wang avatar image John Wang ♦♦ commented ·
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.
0 Likes 0 ·
drew-bolton10590 avatar image drew-bolton10590 commented ·
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.
0 Likes 0 ·
John Wang avatar image John Wang ♦♦ commented ·
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
0 Likes 0 ·
Tyler Liu avatar image Tyler Liu ♦ commented ·
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
0 Likes 0 ·
Tyler Liu avatar image
Tyler Liu answered drew-bolton10590 commented
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.
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.

drew-bolton10590 avatar image drew-bolton10590 commented ·
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.
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