cannot create new collaboration using the nodeJS box sdk
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 (https://github.com/box/box-node-sdk/blob/master/docs/collaborations.md) 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 using the API (https://developer.box.com/reference#add-a-collaboration) directly and I was able to update and set the correct role for my folder.
Though, I would like to run it from my node app and use the node sdk directly.
Does anyone know why this would not work ?
-
This should work...
adminAPIClient.enterprise.getUsers({filter_term: FOLDER_OWNER_EMAIL}, function (err, users) { var owner = users.entries[0]; var userAPIClient = sdk.getAppAuthClient('user', owner.id); // folder owner id userAPIClient.collaborations.createWithUserID( APP_USER_ID, FOLDER_ID, userAPIClient.collaborationRoles.EDITOR, function(err, data) { console.log(err); });
}); -
Thanks ,
I understand why this would work, but for some reason, it does not work on my side - it might have to do with the service account or app user that I have.
my users are created as app user through the following API:
const createAppUser = function(userName) { console.log(`create user ${userName}`); var requestParams = { body: { name: userName, is_platform_access_only: true } }; //Get App auth client const boxAdminClient = BoxSdk.getAppAuthClient('enterprise', process.env.BOX_ENTERPRISE_ID); return new Promise(function (resolve, reject) { //Create the user in Box boxAdminClient.post('/users', requestParams, boxAdminClient.defaultResponseHandler(function(e rror, boxResponse) { if (error) { console.log(`error when creating user ${error}`); reject(error); } resolve(boxResponse); })); }); };
Then I have my app user and I want to assign this user to a specific folder
// appUserId is the id of the app user previously created const assignUserToFolder = function(appUserId) { /***phone number removed for privacy***is the owner of the folder (its also the owner of the account so real user) var appUserClient = BoxSdk.getAppAuthClient('user',***phone number removed for privacy***'); console.log(`assign user ${appUserId} to folder ${process.env.BOX_FOLDER_ID}`); appUserClient.collaborations.createWithUserID( appUserId, process.env.BOX_FOLDER_ID, appUserClient.collaborationRoles.EDITOR, ( function (error, boxResponse) { console.log('creating collaboration'); if (error) { console.log(`error ${error}`); } console.log(`update collaboration ${boxResponse}`); })); };
but for some reason, it seems the call to collaborations.createWithUserID is not even made as I dont get any output in log
Thanks,
Fred
Please sign in to leave a comment.
Comments
2 comments