Question

send fax using curl

  • 11 February 2019
  • 7 replies
  • 2399 views

Hi, I am trying to send fax using curl. I can send it via my localhost. But when I am uploading code to server and try to send it with attachment it is showing some error like:

[errorCode] => MSG-356

[message] => Either filename or content type should be specified, attachment [1]: []

[attachmentFileName] =>

[attachmentNumber] => 1.


I think It has some error in following part of code:


$file_name_with_full_path = ('public/pdf/'.$item[0]['item_id'].'-'.$random_number.'_doc.pdf');


curl_setopt($ch, CURLOPT_POSTFIELDS, array(

'username' => '+123456789',

'password' => "abc@1234",

'to' => '+12457899',

'from'=>'+795454663',

'attachment' => '@'.$file_name_with_full_path,

'contentType'=>'application/pdf',


));





7 replies

Have you read this article: https://medium.com/ringcentral-developers/use-curl-to-access-ringcentral-platform-api-d4710fe68fa4 ?

There is a sample for fax sending
Userlevel 1
First of all, is there any reason you don't want to use our SDKs? Using our SDKs is the most convenient way to access RingCentral platform and call the APIs. What programming language do you use? https://github.com/ringcentral

If you still want to write from scratch using curl, see the example from the API explorer https://developer.ringcentral.com/api-reference#Fax-sendFaxMessage

+ Phong
I am using php. Could you please send me complete code of send fax with attachment becouse I faced some authentication problem when I tried using sdk.
My code is working properly on localhost but it is not working on server.
Here is my code:- Credentials are dummy 
/////////////////////////////////////////////////////////////////////////////////////
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://platform.devtest.ringcentral.com/restapi/oauth/token");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "username=+15450345789&password=2145854#&extension=101&grant_type=password");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERPWD, "kukadkashjasd" . ":" . "f9ReaNa3TSe1RYx8hS-8jahdkjdsjhadhjkjahds");

$headers = array();
$headers[] = "Accept: application/json";
$headers[] = "Content-Type: application/x-www-form-urlencoded";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);

$result = json_decode($result);
if (curl_errno($ch)) {
   echo 'Error:' . curl_error($ch);
}
  $token = $result->access_token;
curl_close($ch);
$ch = curl_init();   

            $url = "https://platform.devtest.ringcentral.com/restapi/v1.0/account/~/extension/~/fax";
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, array(
        'username'      => '+15450345789',
        'password'      => "2145854",
        'to'     => '+9874563210',
        'from'=>'+142452454565',
        'attachment'    => '@' . realpath('/var/www/html/pdf2-199167_doc.pdf'),
        'coverpagetext' => 'PHP FaxOut Via cURL'
    ));
            $dataarray =array(
                              'accept: application/json',
                              'authorization: Bearer '.$token
                              );
            curl_setopt($ch, CURLOPT_HTTPHEADER, $dataarray);

            $response = curl_exec($ch);
            curl_close($ch);
            $data = (json_decode($response));
            echo '<pre>';
print_r($data); exit;
/////////////////////////////////////////////////////////////////////////////////////////////
It is working perfect on my local server. But when I upload it to server,
I am getting this error:-

    [errorCode] => InvalidContent
    [message] => Either filename or content type should be specified, attachment [1]: []
    [errors] => Array
        (
            [0] => stdClass Object
                (
                    [errorCode] => MSG-356
                    [message] => Either filename or content type should be specified, attachment [1]: []
                    [attachmentFileName] => 
                    [attachmentNumber] => 1
                )

        )

    [attachmentFileName] => 
    [attachmentNumber] => 1
)
Userlevel 1
First of all, what issue did you face when you use the RingCentral SDK to get authentication? If your app is password flow, check out this tutorial

Secondly, if your code works well on localhost, your code to call RingCentral fax endpoint must be correct. Now, if it does not work on your remote server and the complaint is about the attachment, the problem is most likely with your file on the server or as you said, some "permission" issue setting for your server that I cannot be aware of.

This is not a RingCentral API problem but I guess our server cannot reach the attachment file with the specified path realpath('/var/www/html/pdf2-199167_doc.pdf'). Can you put the file somewhere that it could be accessible e.g. from the browser and use that link.

I strongly recommend you to try the SDK again.

+ Phong
Sir could you please send me complete code step by step to send fax with attachment using RingCentral SDK in php?
Hello Sir.
I tried through SDK and now I am getting this error:-


login/relogin
Exception: Resource Owner credentials are incomplete
SDK HTTP Error at https://platform.devtest.ringcentral.com/restapi/oauth/token
Response text: {
  "error" : "invalid_request",
  "error_description" : "Resource Owner credentials are incomplete",
  "errors" : [ {
    "errorCode" : "OAU-143",
    "message" : "Resource Owner credentials are incomplete"
  } ]
}

Reply