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
fax attachment getMessageContent failing with error:"Sandbox client is not allowed:
Tags: rest api, fax, javascript
Nov 4, 2021 at 9:30am   •   5 replies  •  0 likes
Ajay Wadhawan

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)

5 Answers
answered on Nov 4, 2021 at 12:53pm  

 0
on Nov 4, 2021 at 1:01pm   •  0 likes

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)
}
answered on Nov 4, 2021 at 12:22pm  

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


 0
on Nov 4, 2021 at 12:34pm   •  0 likes

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

answered on Nov 4, 2021 at 12:09pm  

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;
}
}

 0
answered on Nov 4, 2021 at 12:09pm  

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; } 
}

 0
answered on Nov 4, 2021 at 12:39pm  

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.


 0
on Nov 4, 2021 at 12:46pm   •  0 likes

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)
answered on Nov 4, 2021 at 11:39am  

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);
      })
}

 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