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
send fax using curl
Tags: fax
Feb 11, 2019 at 2:53am   •   7 replies  •  0 likes
nikunj-bhatnagar

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 Answers
answered on Feb 12, 2019 at 10:29pm  
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"
  } ]
}

 0
answered on Feb 12, 2019 at 9:29pm  
Sir could you please send me complete code step by step to send fax with attachment using RingCentral SDK in php?

 0
answered on Feb 12, 2019 at 9:27am  
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

 0
answered on Feb 12, 2019 at 2:32am  
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
answered on Feb 11, 2019 at 9:11pm  
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.

 0
answered on Feb 11, 2019 at 8:45am  
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

 0
answered on Feb 11, 2019 at 8:33am  

 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