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
Sending fax with php code, Fax sending without attachments.
Tags: getting started
May 29, 2019 at 12:26am   •   2 replies  •  0 likes
fax number

<?php

$ch = curl_init();

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

curl_setopt($ch, CURLOPT_URL, "https://platform.ringcentral.com/restapi/oauth/token");

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS, "username=+xxxxxx&password=password#&extension=102&grant_type=password");

curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_USERPWD, "PYS9kaDdSey5j72ljRCfDw" . ":" . "JV4wWOkJTX5sJf-OZDD_fgJJ-uZODeSPeXxdhMUtsTAN");


$headers = array();

$headers[] = "Accept: application/json";

$headers[] = "Content-Type: application/x-www-form-urlencoded";

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);


$result = curl_exec($ch);

$results = (json_decode($result));

$token = $results -> access_token;


$ch = curl_init();

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

curl_setopt($ch, CURLOPT_URL, "https://platform.ringcentral.com/restapi/v1.0/account/~/extension/~/fax");

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_POST,1);

curl_setopt($ch, CURLOPT_POSTFIELDS, array(

'from' => '+xxxxx',

'to' => '+xxxxxx',

'name'=>'sample.pdf',

'attachments'=> '@'.realpath('sample.pdf'),

'coverpagetext' => 'PHP FaxOut Via cURL'

));

$headers = array();

$headers[] = "Accept: application/json";

$headers[] = "Accept: application/pdf";

$headers[] = "Authorization: Bearer $token";

$headers[] = "Content-Type: multipart/form-data";

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);


$result1 = curl_exec($ch);

print_r($result1);


if (curl_errno($ch)) {

echo 'Error:' . curl_error($ch);

}

curl_close ($ch);


?>


Response


{ "uri" : "https://platform.ringcentral.com/restapi/v1.0/account/628394008/extension/628447008/message-store/986620102017", "id" : 986620102017, "to" : [ { "phoneNumber" : "+12158600723", "location" : "Newtown, PA", "messageStatus" : "Queued" } ], "type" : "Fax", "creationTime" : "2019-05-29T07:09:48.000Z", "readStatus" : "Unread", "priority" : "Normal", "attachments" : [ { "id" : 986620102017, "uri" : "https://media.ringcentral.com/restapi/v1.0/account/628394008/extension/628447008/message-store/986620102017/content/986620102017", "type" : "RenderedDocument", "contentType" : "application/pdf" } ], "direction" : "Outbound", "availability" : "Alive", "messageStatus" : "Queued", "faxResolution" : "High", "faxPageCount" : 0, "lastModifiedTime" : "2019-05-29T07:09:48.752Z", "coverIndex" : 7 }

1 Answer
answered on May 30, 2019 at 8:52am  

Sorry I did not understand the question from the title.

It is not the way to send file attachments like that. There is no boundary attached to multipart-form-data either.

Is there a reason why you have to use curl to send a fax? Using the RingCentral PHP SDK would help you simply your code and handle lots of overhead exception handlings. Look at this quick start to see how easy to send a fax using the SDK.

If you insist to use curl, let me know so I can spare some time to write it for you or read this


 0
answered on May 29, 2019 at 7:43am  

What is your question? Or is that you just want to share your code?


 0



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