I am building an app that uses box, and I want to add a collaboration on my folder for a given user.
Looking at box doc I am doing the following :
const assignUserToFolder = function(appUserId) {
//Get App auth client
const boxAdminClient =
BoxSdk.getAppAuthClient('enterprise', process.env.BOX_ENTERPRISE_ID);
console.log(`assign user ${appUserId} to folder ${process.env.BOX_FOLDER_ID}`);
boxAdminClient.collaborations.createWithUserID(
appUserId,
process.env.BOX_FOLDER_ID,
boxAdminClient.collaborationRoles.EDITOR, (
function (error, boxResponse) {
if (error) {
console.log(`error ${error}`);
}
}));
};
I have verified that the box client is correct and appUserId and the folderId have correct values.
I have also tested directly using the API directly and I was able to update and set the correct role for my folder.
but even when I put the equivalent to my node code
const assignUserToFolderAPI = function(appUserId) {
var requestParams = {
body: {
item: {
id: process.env.BOX_FOLDER_ID,
type: "folder"
},
accessible_by: {
id: appUserId,
type: "user"
},
role: "editor"
}
};
//Get App auth client
const boxAdminClient = BoxSdk.getAppAuthClient('enterprise', process.env.BOX_ENTERPRISE_ID);
return new Promise(function (resolve, reject) {
//Create the collaboration in Box
console.log(`create collaboration for user ${appUserId}`);
boxAdminClient.post('/collaborations', requestParams, boxAdminClient.defaultResponseHandler(function(error, boxResponse) {
if (error) {
reject(error);
console.log(requestParams);
}
resolve(boxResponse);
}));
});
};
I get the following error messsage
"errorMessage": "Unexpected API Response [404 Not Found] (not_found: \"Not Found\")",
When I review the requestParams, both item.id
and accessible_by.id
are correct, and it works just fine from CLI.
Does anyone know why this would not work ? could it be an issue with the service account I am using ?
In the box app:
- Application Access is Enterprise
- I've selected all Application Scopes