Skip to main content

<?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 }

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


Reply