Fax sent from API but status is Sending failed php

  • 1
  • Problem
  • Updated 1 year ago
I am trying to Send Fax from PHP SDK it works and providing a sent URL but after that when i check the status of fax it is sending failed.
Photo of Tayyab Sajjad

Tayyab Sajjad

  • 364 Points 250 badge 2x thumb

Posted 1 year ago

  • 1
Photo of Tyler Long

Tyler Long, Official Rep

  • 6,288 Points 5k badge 2x thumb
Please provide the sample code and detailed response.
Photo of Tayyab Sajjad

Tayyab Sajjad

  • 364 Points 250 badge 2x thumb
<?php

require_once('_bootstrap.php');

use RingCentral\SDK\SDK;

// Create SDK instance

$credentials = require('_credentials.php');

$rcsdk = new SDK('', '', 'https://platform.devtest.ringcentral.com', 'app1', '1.0.0');

$platform = $rcsdk->platform();

// Retrieve previous authentication data

$cacheDir = __DIR__ . DIRECTORY_SEPARATOR . '_cache';
$file = $cacheDir . DIRECTORY_SEPARATOR . 'platform.json';

if (!file_exists($cacheDir)) {
    mkdir($cacheDir);
}

$cachedAuth = array();

if (file_exists($file)) {
    $cachedAuth = json_decode(file_get_contents($file), true);
    unlink($file); // dispose cache file, it will be updated if script ends successfully
}

$platform->auth()->setData($cachedAuth);

try {

    $platform->refresh();
$request = $rcsdk->createMultipartBuilder()
                 ->setBody(array(
                     'to'         => array(
                         array('phoneNumber' => '12673314004'),
                     ),
                     'faxResolution' => 'High',
                 ))
                 ->add('Plain Text', 'file.txt')
                 ->add(fopen('D:/wamp/www/vendor/ringcentral/ringcentral-php/demo/file.txt', 'r'))
                 ->request('/account/~/extension/~/fax'); // also has optional $method argument

$response = $platform->sendRequest($request);

print 'Sent Fax ' . $response->json()->uri . PHP_EOL;
    print 'Authorization was restored' . PHP_EOL;

} catch (Exception $e) {

    print 'Auth exception: ' . $e->getMessage() . PHP_EOL;

    $auth = $platform->login($credentials['username'], $credentials['extension'], $credentials['password']);

    print 'Authorized' . PHP_EOL;

}

// Save authentication data

file_put_contents($file, json_encode($platform->auth()->data(), JSON_PRETTY_PRINT));
Photo of Tayyab Sajjad

Tayyab Sajjad

  • 364 Points 250 badge 2x thumb
Photo of Tyler Long

Tyler Long, Official Rep

  • 6,288 Points 5k badge 2x thumb
Could you please also provide the detailed content of $response = $platform->sendRequest($request);  ?  Are there any exceptions? If so, please post them.

I have to go offline now because it's out of my working hours. We have several Developer Relationship Engineers in different timezones and others will continue to respond.
(Edited)
Photo of Tayyab Sajjad

Tayyab Sajjad

  • 364 Points 250 badge 2x thumb
there is no exception it sent successfully but after Queued it gets failed
Photo of Tayyab Sajjad

Tayyab Sajjad

  • 364 Points 250 badge 2x thumb
i am getting this response while sending Fax.
D:\wamp\www\vendor2\ringcentral\ringcentral-php\demo\authData.php:58:
object(RingCentral\SDK\Http\ApiResponse)[48]
  protected '_jsonAsArray' => null
  protected '_jsonAsObject' => null
  protected '_multiparts' => null
  protected '_response' => 
    object(GuzzleHttp\Psr7\Response)[46]
      private 'reasonPhrase' => string 'OK' (length=2)
      private 'statusCode' => int 200
      private 'headers' => 
        array (size=13)
          'Server' => 
            array (size=1)
              ...
          'Date' => 
            array (size=1)
              ...
          'Content-Type' => 
            array (size=1)
              ...
          'Content-Length' => 
            array (size=1)
              ...
          'Connection' => 
            array (size=1)
              ...
          'RCRequestId' => 
            array (size=1)
              ...
          'RoutingKey' => 
            array (size=1)
              ...
          'Content-Language' => 
            array (size=1)
              ...
          'Vary' => 
            array (size=1)
              ...
          'X-Rate-Limit-Group' => 
            array (size=1)
              ...
          'X-Rate-Limit-Limit' => 
            array (size=1)
              ...
          'X-Rate-Limit-Remaining' => 
            array (size=1)
              ...
          'X-Rate-Limit-Window' => 
            array (size=1)
              ...
      private 'headerNames' => 
        array (size=13)
          'server' => string 'Server' (length=6)
          'date' => string 'Date' (length=4)
          'content-type' => string 'Content-Type' (length=12)
          'content-length' => string 'Content-Length' (length=14)
          'connection' => string 'Connection' (length=10)
          'rcrequestid' => string 'RCRequestId' (length=11)
          'routingkey' => string 'RoutingKey' (length=10)
          'content-language' => string 'Content-Language' (length=16)
          'vary' => string 'Vary' (length=4)
          'x-rate-limit-group' => string 'X-Rate-Limit-Group' (length=18)
          'x-rate-limit-limit' => string 'X-Rate-Limit-Limit' (length=18)
          'x-rate-limit-remaining' => string 'X-Rate-Limit-Remaining' (length=22)
          'x-rate-limit-window' => string 'X-Rate-Limit-Window' (length=19)
      private 'protocol' => string '1.1' (length=3)
      private 'stream' => 
        object(GuzzleHttp\Psr7\Stream)[44]
          private 'stream' => resource(66, stream)
          private 'size' => null
          private 'seekable' => boolean true
          private 'readable' => boolean true
          private 'writable' => boolean true
          private 'uri' => string 'php://temp' (length=10)
          private 'customMetadata' => 
            array (size=0)
              ...
  protected '_request' => 
    object(GuzzleHttp\Psr7\Request)[37]
      private 'method' => string 'POST' (length=4)
      private 'requestTarget' => null
      private 'uri' => 
        object(GuzzleHttp\Psr7\Uri)[21]
          private 'scheme' => string 'https' (length=5)
          private 'userInfo' => string '' (length=0)
          private 'host' => string 'platform.devtest.ringcentral.com' (length=32)
          private 'port' => null
          private 'path' => string '/restapi/v1.0/account/~/extension/~/fax' (length=39)
          private 'query' => string '' (length=0)
          private 'fragment' => string '' (length=0)
      private 'headers' => 
        array (size=6)
          'Host' => 
            array (size=1)
              ...
          'Content-Type' => 
            array (size=1)
              ...
          'Authorization' => 
            array (size=1)
              ...
          'User-Agent' => 
            array (size=1)
              ...
          'RC-User-Agent' => 
            array (size=1)
              ...
          'Expect' => 
            array (size=1)
              ...
      private 'headerNames' => 
        array (size=6)
          'content-type' => string 'Content-Type' (length=12)
          'authorization' => string 'Authorization' (length=13)
          'user-agent' => string 'User-Agent' (length=10)
          'rc-user-agent' => string 'RC-User-Agent' (length=13)
          'host' => string 'Host' (length=4)
          'expect' => string 'Expect' (length=6)
      private 'protocol' => string '1.1' (length=3)
      private 'stream' => 
        object(GuzzleHttp\Psr7\MultipartStream)[22]
          private 'boundary' => string 'de8542ac0534cffa01ee24f9f9d509f1a6770ea3' (length=40)
          public 'stream' => 
            object(GuzzleHttp\Psr7\AppendStream)[23
              ...




Every Fax is in Sending failed status after Queued status.
But SMS are sending successfully.
Photo of Paco Vu

Paco Vu

  • 426 Points 250 badge 2x thumb
Hi Tayyab,

Your code looks ok and it looks exactly the same as the demo code for PHP SDK.

I just doubt that the number you were trying to sent a fax was the one that cannot receive a fax message (presumed that it was the real number you were sending to!). So I tested sending a fax to that number from my test app and it also failed. Similarly, it failed when I sent a fax to my mobile number. However, the same code would send fax successfully to my RingCentral number or to a real fax number.

Please try again to send fax to a fax machine, or to your other extension number which support fax. You can also try to send to my test number 13129828160

Hope this helps,
Paco
Photo of Tayyab Sajjad

Tayyab Sajjad

  • 364 Points 250 badge 2x thumb
Sent, Please check if you get
Photo of Tayyab Sajjad

Tayyab Sajjad

  • 364 Points 250 badge 2x thumb
i am getting this response when i check it from api explorer of RC
{ "uri": "https://platform.devtest.ringcentral.com/restapi/v1.0/account/207664004/extension/207664004/message-...;, "records": [ { "uri": "https://platform.devtest.ringcentral.com/restapi/v1.0/account/207664004/extension/207664004/message-...;, "id": 3244561004, "to": [ { "phoneNumber": "+13129828160", "messageStatus": "SendingFailed", "faxErrorCode": "RenderingFailed" } ], "type": "Fax", "creationTime": "2017-07-12T15:29:42.000Z", "readStatus": "Unread", "priority": "Normal", "attachments": [ { "id": 3244561004, "uri": "https://media.devtest.ringcentral.com/restapi/v1.0/account/207664004/extension/207664004/message-sto...;, "type": "RenderedDocument", "contentType": "application/pdf" } ], "direction": "Outbound", "availability": "Alive", "messageStatus": "SendingFailed", "faxResolution": "High", "faxPageCount": 0, "lastModifiedTime": "2017-07-12T15:36:51.213Z", "coverIndex": 7 },

Photo of Paco Vu

Paco Vu

  • 426 Points 250 badge 2x thumb
I got a test fax from you!

+ Paco
Photo of Tayyab Sajjad

Tayyab Sajjad

  • 364 Points 250 badge 2x thumb
Look i try 3 times to your number but all failed
{ "uri": "https://platform.devtest.ringcentral.com/restapi/v1.0/account/207664004/extension/207664004/message-...;, "records": [ { "uri": "https://platform.devtest.ringcentral.com/restapi/v1.0/account/207664004/extension/207664004/message-...;, "id": 3244689004, "to": [ { "phoneNumber": "+13129828160", "messageStatus": "SendingFailed", "faxErrorCode": "RenderingFailed" } ], "type": "Fax", "creationTime": "2017-07-12T15:48:15.000Z", "readStatus": "Unread", "priority": "Normal", "attachments": [ { "id": 3244689004, "uri": "https://media.devtest.ringcentral.com/restapi/v1.0/account/207664004/extension/207664004/message-sto...;, "type": "RenderedDocument", "contentType": "application/pdf" } ], "direction": "Outbound", "availability": "Alive", "messageStatus": "SendingFailed", "faxResolution": "High", "faxPageCount": 0, "lastModifiedTime": "2017-07-12T15:54:53.667Z", "coverIndex": 7 }, { "uri": "https://platform.devtest.ringcentral.com/restapi/v1.0/account/207664004/extension/207664004/message-...;, "id": 3244561004, "to": [ { "phoneNumber": "+13129828160", "messageStatus": "SendingFailed", "faxErrorCode": "RenderingFailed" } ], "type": "Fax", "creationTime": "2017-07-12T15:29:42.000Z", "readStatus": "Unread", "priority": "Normal", "attachments": [ { "id": 3244561004, "uri": "https://media.devtest.ringcentral.com/restapi/v1.0/account/207664004/extension/207664004/message-sto...;, "type": "RenderedDocument", "contentType": "application/pdf" } ], "direction": "Outbound", "availability": "Alive", "messageStatus": "SendingFailed", "faxResolution": "High", "faxPageCount": 0, "lastModifiedTime": "2017-07-12T15:36:51.213Z", "coverIndex": 7 } ], "paging": { "page": 1, "totalPages": 1, "perPage": 100, "totalElements": 2, "pageStart": 0, "pageEnd": 1 }, "navigation": { "firstPage": { "uri": "https://platform.devtest.ringcentral.com/restapi/v1.0/account/207664004/extension/207664004/message-...; }, "lastPage": { "uri": "https://platform.devtest.ringcentral.com/restapi/v1.0/account/207664004/extension/207664004/message-...; } }
Photo of AK

AK, Official Rep

  • 4,372 Points 4k badge 2x thumb
Tayyab,

I used the same exact code and I created a new extension on your sandbox account just to verify on behalf of your account. 

It works fine!  For ref: I have created Ext 102

For more information on how the fax is rendered, you could refer to our FAQ below:

Fax  FAQ RingCentral 
Photo of Tayyab Sajjad

Tayyab Sajjad

  • 364 Points 250 badge 2x thumb
but on my RC windows it is fail....
Photo of AK

AK, Official Rep

  • 4,372 Points 4k badge 2x thumb
Can u do a RingCentral Meetings now? I could send in the meeting invite to your email.
Photo of Tayyab Sajjad

Tayyab Sajjad

  • 364 Points 250 badge 2x thumb
yes
Photo of AK

AK, Official Rep

  • 4,372 Points 4k badge 2x thumb
Please check ur inbox, I have sent the meeting invite to:
buttercodeorg@gmail.com
Photo of Tyler Long

Tyler Long, Official Rep

  • 5,190 Points 5k badge 2x thumb
AK, could you please post more detailed information about the meeting? What's the root cause of the problem?  Post it here so it can benefit who also have similar problems.
(Edited)
Photo of Tayyab Sajjad

Tayyab Sajjad

  • 364 Points 250 badge 2x thumb
Thanks @AK(Anil) for helping.
Now the issue is resolved i was selecting wrong platform.
Now i am using Server No UI and my fax are working fine