I'm trying to generate a downscoped token for the Content Uploader UI Element, per the documentation here. But I keep getting stuck when trying to specify a resource.
In the documentation, it says that the desired upload folder should be specified as the resource on the request:
But when I specify my resource using a URI like https://api.box.com/2.0/folders/FOLDER_ID, I consistently get an invalid resource error.
{ error: 'invalid_resource',
error_description: 'The target resource is invalid.' } }
My full code looks like this:
const scopes = 'base_upload';
const folder = process.env.FOLDER_ID;
const resource = `https://api.box.com/2.0/folders/${folder}`
const configJSON = JSON.parse(fs.readFileSync('./box-config.json'));
const sdk = boxSDK.getPreconfiguredInstance(configJSON);
const client = sdk.getAppAuthClient('enterprise');
client.exchangeToken(scopes, folder).then((tokenInfo) => {
// Do stuff
}).catch((err) => {
console.error(err);
});
What am I doing wrong? Am I specifying the folder URI incorrectly?
FWIW, I've tried similar code that does not include a resource parameter on the exchangeToken call. That works in the sense that I get an access token back. But then, when I pass that token to the Content Uploader, it appears the token does not grant access to the folder (I get a 404 error in the browser console that the specified folder cannot be found). I assume that's because the token was not scoped to have access to that folder.