Level up your Box knowledge with brand new learning paths on Box University. Visit training.box.com to get started

cannot create new collaboration using the nodeJS box sdk

New post

Comments

2 comments

  • kendomen

    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);
      });
    });
    0
    Comment actions Permalink
  • fhenri

    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

     

    0
    Comment actions Permalink

Please sign in to leave a comment.