Skip to main content

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)

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

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

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

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


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


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.


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)

Attachment URI: https://platform.ringcentral.com/restapi/v1.0/account/xxxxxxextension/xxxxxxxxx/message-store/404068973008/content/404068973008


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

Reply