Question

PHP SDK Fax Permission Error

  • 15 April 2019
  • 7 replies
  • 1735 views

First time writing an integration using RC's PHP SDK. Installed SDK via Composer and setup the credentials/sandbox, etc. Authorization is fine, app is communicating. Started with the demo/fax.php to test using file.txt (using demo installed with sdk) and I'm getting "Bad Request" but no error code.

I haven't changed anything in the SDK (other than the /path/to/vendor/autoload which is incorrect in _bootstrap)

How can I get more info so I can troubleshoot?

Here's what I'm getting back from RC:

--952ed22a92fb817145143eb568f4a4c84ce5a37b
Content-Type: application/json
Content-Disposition: form-data; name="json"; filename="request.json"
Content-Length: 61

{"to":[{"phoneNumber":"17474773958"}],"faxResolution":"High"}
--952ed22a92fb817145143eb568f4a4c84ce5a37b
Content-Type: application/octet-stream
Content-Disposition: form-data; name="file.txt"; filename="file.txt"
Content-Length: 10

Plain Text
--952ed22a92fb817145143eb568f4a4c84ce5a37b
Content-Disposition: form-data; name="ico_case_crm.png"; filename="ico_case_crm.png"
Content-Type: image/png

<html>
<head>
<META NAME="robots" CONTENT="noindex,nofollow">
<script src="/_Incapsula_Resource?SWJIYLWA=5074a744e2e3d891814e9a2dace20bd4,719d34d31c8e3a6e6fffd425f7e032f3">
</script>
<body>
</body></html>
--952ed22a92fb817145143eb568f4a4c84ce5a37b--

Exception: Bad Request
SDK HTTP Error at https://platform.devtest.ringcentral.com/restapi/v1.0/account/~/extension/~/fax
Response text: {
  "message" : "Bad Request",
  "errors" : [ ]
}
Previous: Response has unsuccessful status
#0 /home/drs/public_html/admin/ring-central/vendor/ringcentral/ringcentral-php/src/Platform/Platform.php(329): RingCentralSDKHttpClient->send(Object(GuzzleHttpPsr7Request))
#1 /home/drs/public_html/admin/ring-central/vendor/ringcentral/ringcentral-php/demo/fax.php(34): RingCentralSDKPlatformPlatform->sendRequest(Object(GuzzleHttpPsr7Request)) 

#2 {main}


7 replies

Hi Nathan,

The demo code does not implement exception handling. Please put the code in "try catch" as shown below to detect the error message.
try {        $rcsdk->platform()->get('/account/~/whatever');    } catch (RingCentralSDKHttpApiException $e) {        // Getting error messages using PHP native interface      print 'Expected HTTP Error: ' . $e->getMessage() . PHP_EOL;        // In order to get Request and Response used to perform transaction:      $apiResponse = $e->apiResponse();      print_r($apiResponse->request());      print_r($apiResponse->response());        // Another way to get message, but keep in mind, that there could be no response if request has failed completely      print '  Message: ' . $e->apiResponse->response()->error() . PHP_EOL;   
}
Thanks Phong, 

It did return an error which appears to be that it can't find the GuzzleHTTP dependency, but it did install in the /vendor/ directory.

Can you gleen any info from this response:

Expected HTTP Error: Resource not found  GuzzleHttpPsr7Request Object  (      [method:GuzzleHttpPsr7Request:private] => GET      [requestTarget:GuzzleHttpPsr7Request:private] =>       [uri:GuzzleHttpPsr7Request:private] => GuzzleHttpPsr7Uri Object          (              [scheme:GuzzleHttpPsr7Uri:private] => https              [userInfo:GuzzleHttpPsr7Uri:private] =>               [host:GuzzleHttpPsr7Uri:private] => platform.devtest.ringcentral.com              [port:GuzzleHttpPsr7Uri:private] =>               [path:GuzzleHttpPsr7Uri:private] => /restapi/v1.0/account/~/whatever              [query:GuzzleHttpPsr7Uri:private] =>               [fragment:GuzzleHttpPsr7Uri:private] =>           )        [headers:GuzzleHttpPsr7Request:private] => Array          (              [Host] => Array                  (                      [0] => platform.devtest.ringcentral.com                  )                [content-type] => Array                  (                      [0] => application/json                  )                [accept] => Array                  (                      [0] => application/json                  )                [Authorization] => Array                  (                      [0] => bearer U0pDMTJQMDFQQVMwMHxBQUFZVjVYenJFenhWellMemhJWktZTmFVTGtHRjBZNFF3cVBHa09Ca3plTW1ORG9CdDIyZXVpWHFaOXNzNUVqZ0lKNF9QWWRPMEVYNEhPV3FzbEwwTUtuLWlvamdZamh1cXc4RWFEc3FFZ0lVTHZ1aEdlX0tXajhRYU5GN21lVWYyM0VDaWpVT0MwenVOQjU4S3ZoS0tfUDhFbVMzVDMxaWdVQ042eTh2bzRTakJzUVlITzRabWNfaU5zZlZVMFpyU0o0c1hSc1ozdUlNUEhjMlk4Y1lnSVd8YUdjSmJ3fFVERENCS2s1QVA1dWhXZ1QzVmdRT3d8QUE                  )                [User-Agent] => Array                  (                      [0] => Unnamed/0.0.0 Linux/2.6.32-042stab133.2 PHP/7.0.33 RCPHPSDK/2.1.2                  )                [RC-User-Agent] => Array                  (                      [0] => Unnamed/0.0.0 Linux/2.6.32-042stab133.2 PHP/7.0.33 RCPHPSDK/2.1.2                  )            )        [headerNames:GuzzleHttpPsr7Request:private] => Array          (              [content-type] => content-type              [accept] => accept              [authorization] => Authorization              [user-agent] => User-Agent              [rc-user-agent] => RC-User-Agent              [host] => Host          )        [protocol:GuzzleHttpPsr7Request:private] => 1.1      [stream:GuzzleHttpPsr7Request:private] => GuzzleHttpPsr7Stream Object          (              [stream:GuzzleHttpPsr7Stream:private] => Resource id #78              [size:GuzzleHttpPsr7Stream:private] => 0              [seekable:GuzzleHttpPsr7Stream:private] => 1              [readable:GuzzleHttpPsr7Stream:private] => 1              [writable:GuzzleHttpPsr7Stream:private] => 1              [uri:GuzzleHttpPsr7Stream:private] => php://temp              [customMetadata:GuzzleHttpPsr7Stream:private] => Array                  (                  )            )    )  GuzzleHttpPsr7Response Object  (      [reasonPhrase:GuzzleHttpPsr7Response:private] => Not Found      [statusCode:GuzzleHttpPsr7Response:private] => 404      [headers:GuzzleHttpPsr7Response:private] => Array          (              [Server] => Array                  (                      [0] => nginx                  )                [Date] => Array                  (                      [0] => Mon, 15 Apr 2019 17:53:20 GMT                  )                [Content-Type] => Array                  (                      [0] => application/json                  )                [Content-Length] => Array                  (                      [0] => 83                  )                [Connection] => Array                  (                      [0] => keep-alive                  )                [RoutingKey] => Array                  (                      [0] => SJC12P01                  )                [RCRequestId] => Array                  (                      [0] => 5b57ee94-5fa7-11e9-bb0c-005056bba23b                  )            )        [headerNames:GuzzleHttpPsr7Response:private] => Array          (              [server] => Server              [date] => Date              [content-type] => Content-Type              [content-length] => Content-Length              [connection] => Connection              [routingkey] => RoutingKey              [rcrequestid] => RCRequestId          )        [protocol:GuzzleHttpPsr7Response:private] => 1.1      [stream:GuzzleHttpPsr7Response:private] => GuzzleHttpPsr7Stream Object          (              [stream:GuzzleHttpPsr7Stream:private] => Resource id #80              [size:GuzzleHttpPsr7Stream:private] =>               [seekable:GuzzleHttpPsr7Stream:private] => 1              [readable:GuzzleHttpPsr7Stream:private] => 1              [writable:GuzzleHttpPsr7Stream:private] => 1              [uri:GuzzleHttpPsr7Stream:private] => php://temp              [customMetadata:GuzzleHttpPsr7Stream:private] => Array                  (                  )            )   
)
Also, it's returning this URL: https://platform.devtest.ringcentral.com/restapi/v1.0/account/258637004/extension/258637004/message-...

Where the Message changes each time; not sure where the account and extension variables are coming from, they are not part of the Sandbox credentials.
You original web post specifies 

Content-Disposition: form-data; name="ico_case_crm.png"; filename="ico_case_crm.png" . Content-Type: image/png

However its content is <html> ...

You were sending HTML while you told the server that it's an image, it woundn't work.
Hello Tyler,

Thank you for responding.

The ico_case_crm.png file was left over from the "out of the box" demo which didn't work.  I wrote a new page to test and it does work - and that page faxes an HTML document.

However, I'm still having trouble with images.  I have changed them to base64 data uri and they still do not appear on the fax.  Here's an example of the embedding syntax - any idea why it will not show up on the fax?

    <img src="data: image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA2ODAgMiI+PGRlZnM+PHN0eWxlPi5he2ZpbGw6bm9uZTtzdHJva2U6IzIzMWYyMDtzdHJva2UtbWl0ZXJsaW1pdDoxMDtzdHJva2Utd2lkdGg6MnB4O308L3N0eWxlPjwvZGVmcz48dGl0bGU+cG1wLWxpbmU8L3RpdGxlPjxsaW5lIGNsYXNzPSJhIiB5MT0iMSIgeDI9IjY4MCIgeTI9IjEiLz48L3N2Zz4=" width="680" height="5" style="width: 680px; height: 5px;" />

Hi Nathan,

I just tested and got the same issue. I checked the issue with an engineer and it turns out that we don't render html page as a fax attachment with any other element but texts. So no controls such as checkboxes, radio buttons, table with borders etc. and no images.

So unfortunately, it seems you have to convert to pdf or kind a "screenshot" image then send.

+ Phong
Hello Phong,

Thanks for following up!

Okay, I guess I'll have to convert to PDF first; I was hoping to avoid that.

Maybe a last question (maybe)... I noticed that when I was testing, that if I submitted more than FOUR tests per minute, they were blocked for "too many requests".  Once in production, I'm guessing the client will do 20 or 30 hits within a 5 minute window three or four times per day.  Since the system automatically queue's faxes, why is there a hit limit? And, is there any way to have that lifted?



Reply