Skip to main content
Question

Nodejs SDK - Download File - access_denied_insufficient_permissions - Access denied

  • May 22, 2025
  • 1 reply
  • 46 views

Forum|alt.badge.img

We are using the box nodejs sdk. I cannot download a file via API. Reading a directory / files is working great. When I will use the fileID to download the file to process it in my script I always get:

Error on Download Error: Unexpected API Response [403 Forbidden | 98ye1xgr46e3s3y2.015610c39a9363c40e9d179fae0f64a6c] access_denied_insufficient_permissions - Access denied - insufficient permission

Im using OAuth with the service Account and already have given write access to the folder. The user is also Co-Owner of the directory.

Im trying since hours to figure it out. What am I missing?

Code:
____________________________________

// Get Client
const sdkConfig = require('./box.config.json');
const sdk = BoxSDK.getPreconfiguredInstance(sdkConfig);
const client = sdk.getAppAuthClient('enterprise', sdkConfig.enterpriseID);
// Working Code for Folder-Contents
client.folders.getItems(folderId, { fields: 'id,type,name,modified_at,modified_by' });
// Download a File with fileId (!! Not working)
client.files.getReadStream(fileId, null, (error, stream) => {
if (error) {
console.error('Error on Download', error.toString());
return;
}

// write the file to disk
const output = fs.createWriteStream(targetPath);
stream.pipe(output);
});

 

1 reply

Forum|alt.badge.img

I have solved the Issue. You have to manually reauthorize your app, when you make any changes to the scope. Also you need the "write" scope, so the download can be logged. Also make sure, that the service Account of the app is collaborator in the desired folder / file.