question

Ajay Wadhawan avatar image
Ajay Wadhawan asked Phong Vu commented

fax attachment getMessageContent failing with error:"Sandbox client is not allowed:

Getting this error when I try to download an attachment: Error: Sandbox client is not allowed: xxxxxx. This is our clientId for the sandbox for Fax340b application. Exact scenario is : 1) Received Inbound Fax Event notification. 2) Successfully login into account 3) call get call it is failing with this error. 4) the login info is same as used to subscribe to the incoming fax event. Code snippet below: Followed by call stack.

async function getMessageFromNotification ( uri : string ): Promise < any >
{ const rc = new RingCentral ( { clientId : process . env . RINGCENTRAL_CLIENTID ,
clientSecret : process . env . RINGCENTRAL_CLIENTSECRET ,
server : process . env . SERVER_SANDBOX , } ) ;
await login ( rc , uri ) ;
}
async function login ( rc : RingCentral , uri : string ) {
// Log into RingCentral
var platform = rc . platform () ;
platform . login ( { username : process . env . RINGCENTRAL_USERNAME ,
password : process . env . RINGCENTRAL_PASSWORD ,
extension : process . env . RINGCENTRAL_EXTENSION , } ) ;
platform . on ( platform . events . loginError , function ( e )
{ console . log ( " Login Error ", e . message ) } ) ;
platform . on ( platform . events . rateLimitError , function ( e )
{ console . log ( " Login ErrorRateLimit ", e . message ) } ) ;
platform . on ( platform . events . loginSuccess , function ( e )
{
console . log ( " Login success INBOUND " )
getMessageContent ( platform , uri ) ;
} ) ; //console.log("login success");
}
async function getMessageContent ( platform : any , uri : string ) {
try {
var resp = await platform . get ( uri )
var body = await resp . body ;
await uploadFaxMessageContentToBlob ( body ," application/pdf " ) ; //"image/*")
console . log ( " Ready to receive incoming FAX via WebHook. " )
}
catch ( e )
{
console . error ( e . message ) ; throw e ;
}
}


------error and stack---------

(node:70196) UnhandledPromiseRejectionWarning: Error: Sandbox client is not allowed: KTHkwJaQRUiu6es5YR5lOw [2021-11-03T16:57:55.109Z] at Client.<anonymous> (/Users/ajaywadhawan/dev/ch/coach-infrastructure/AzureFunctions/node_modules/@ringcentral/sdk/lib/http/Client.js:115:35) [2021-11-03T16:57:55.109Z] at step (/Users/ajaywadhawan/dev/ch/coach-infrastructure/AzureFunctions/node_modules/@ringcentral/sdk/lib/http/Client.js:56:23) [2021-11-03T16:57:55.110Z] at Object.next (/Users/ajaywadhawan/dev/ch/coach-infrastructure/AzureFunctions/node_modules/@ringcentral/sdk/lib/http/Client.js:37:53) [2021-11-03T16:57:55.110Z] at fulfilled (/Users/ajaywadhawan/dev/ch/coach-infrastructure/AzureFunctions/node_modules/@ringcentral/sdk/lib/http/Client.js:28:58) [2021-11-03T16:57:55.110Z] at processTicksAndRejections (internal/process/task_queues.js:93:5)

rest apifax
1 |3000

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

Phong Vu avatar image
Phong Vu answered

This is how you can download Fax attachments using JS SDK. Provided that the attachments is an array object you got from a fax message-store record.

var async = require('async')
function downloadAttachments(attachments){
    async.each(attachments,
      async function(attachment, callback){
        var fileName = ""
        var fileNameExt = attachment.contentType.split("/")
        fileName = "fax_attachment_" + attachment.id + "." + fileNameExt[1]
        var resp = await platform.get(attachment.uri)
        var buffer = await resp.buffer()
        fs.writeFileSync(fileName, buffer);
      })
}
1 |3000

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

Ajay Wadhawan avatar image
Ajay Wadhawan answered

This is exactly what I am doing. I think am getting an authorization error when I call get.

] Error in get URI: Sandbox client is not allowed: KTHkwJaQRUiu6es5YR5lOw


async function getMessageContent ( platform : any , uri : string ) {
try {
var resp = await platform . get ( uri ) ;
console . log ( " get attachment called. " ) ;
var buffer = await resp . buffer ;
console . log ( " get attachment being buffered. " ) ;
//await uploadFaxMessageContentToBlob(buffer,"application/pdf");//"image/*")
} catch ( e ) {
console . error ( " Error in get URI: " + e . message ) ;
//throw e;
}
}
1 |3000

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

Ajay Wadhawan avatar image
Ajay Wadhawan answered Phong Vu commented

exception is thrown the sdk file client.js line 115, sendRequest() function. For getting a bad response.

Error: Sandbox client is not allowed: KTHkwJaQRUiu6es5YR5lOw\n at Client.<anonymous> (/Users/ajaywadhawan/dev/ch/coach-infrastructure/AzureFunctions/node_modules/@ringcentral/sdk/lib/http/Client.js:115:35)\n

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.

Phong Vu avatar image Phong Vu ♦♦ commented ·

Are you testing on sandbox and login with a user in your sandbox?

0 Likes 0 ·
Ajay Wadhawan avatar image
Ajay Wadhawan answered Phong Vu commented

Yes . Sending a fax from the same number to the same number.

Sending works fine, Subcribe/Get new Fax notification also works fine, But I am getting this error when try to download the attachment. It is not a problem when I use try in RC developer portal. There I am logged in with my corporate account.

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.

Phong Vu avatar image Phong Vu ♦♦ commented ·

Can you print and share the uri? Mask the account and extension id if you want.

async function getMessageContent(platform:any, uri:string) {
 console.log(uri)
0 Likes 0 ·
Ajay Wadhawan avatar image
Ajay Wadhawan answered Phong Vu commented
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.

Phong Vu avatar image Phong Vu ♦♦ commented ·

You see, you try to access/download a fax from your production using a sandbox app. Where did you read and got that uri?

This domain indicates your production platform.ringcentral.com/.......

It must be media.devtest.ringcentral.com/

Your code to read the message store should be something like this

var endpoint = '/restapi/v1.0/account/~/extension/~/message-store'
try {
    var params = {
        dateFrom: '2021-07-01T00:00:00.000Z',
        dateTo: '2021-10-11T23:59:59.999Z',
        messageType: 'Fax'
    }
    var resp = await platform.get(endpoint, params)
    var jsonObj = await resp.json()
    if (jsonObj.records.length){
        for (var record of jsonObj.records){
            if (record.hasOwnProperty('attachments'))
                downloadAttachments(record.attachments)
         }
    }
}catch(ex){
    console.log(ex.message)
}
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