question

nikunj-bhatnagar13996 avatar image
nikunj-bhatnagar13996 asked Leonard leWang Deactivated edited

send fax using curl

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',


));




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 nikunj-bhatnagar13996 commented
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
2 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.

nikunj-bhatnagar13996 avatar image nikunj-bhatnagar13996 commented ·
Yes I read it. Please send me complete code of send fax with attachment in php. I am newbie for curl also I am not able to understand it.
0 Likes 0 ·
nikunj-bhatnagar13996 avatar image nikunj-bhatnagar13996 commented ·
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
)

0 Likes 0 ·
Phong Vu avatar image
Phong Vu answered
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
1 |3000

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

nikunj-bhatnagar13996 avatar image
nikunj-bhatnagar13996 answered
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.
1 |3000

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

nikunj-bhatnagar13996 avatar image
nikunj-bhatnagar13996 answered nikunj-bhatnagar13996 commented
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
)
2 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.

Tyler Liu avatar image Tyler Liu ♦ commented ·
I don't think it is a localhost/server issue.

The files you are trying to send on server is different from the one on localhost. Could you please double check.

If you have issue with the PHP SDK:  https://github.com/ringcentral/ringcentral-php could you please create a GitHub issue there?


0 Likes 0 ·
nikunj-bhatnagar13996 avatar image nikunj-bhatnagar13996 commented ·
Sir I triple checked. Code is same. Could you please check my code and error. I thing there is some permission issue of curl on server. Curl is not able to fetch the file from path.
0 Likes 0 ·
Phong Vu avatar image
Phong Vu answered
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
1 |3000

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

nikunj-bhatnagar13996 avatar image
nikunj-bhatnagar13996 answered Tyler Liu commented
Sir could you please send me complete code step by step to send fax with attachment using RingCentral SDK in php?
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.

Tyler Liu avatar image Tyler Liu ♦ commented ·
0 Likes 0 ·
nikunj-bhatnagar13996 avatar image
nikunj-bhatnagar13996 answered nikunj-bhatnagar13996 commented
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"
  } ]
}
2 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.

Tyler Liu avatar image Tyler Liu ♦ commented ·
Please double check your clientID, clientSecret, username & password.
0 Likes 0 ·
nikunj-bhatnagar13996 avatar image nikunj-bhatnagar13996 commented ·
Its done sir. Every thing was correct. I did it through ringcentral lite.
Now I have another problem. I have records of inbound and outbound fax in my project. I am getting the records but if I want do download any record I is not working.
Please suggest me how to download it.
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