Accessing collaborating folder with DEVELOPER-TOKEN and not with APP-USER
Hi guys,
i want to integrate the app box of a partner company in our system. the partner company creates a collaborating
folder for the corporation. I also create a App to be able to configure the accessing on the collaborating folder.
the collaborating folder is a subfolder of the root folder.
i am confused because i can access the collaborating folder and files in there with DEVELOPER-TOKEN.
by trying the same with an programmatically created APP-USER nothing works.
It is even not possible to create a collaboration programmatically with the APP-USER on the collaborating folder.
I would appreciate any help :).
// part with the developer token public static void main(String[] args) { // Turn off logging to prevent polluting the output. Logger.getLogger("com.box.sdk").setLevel(Level.OFF); BoxAPIConnection api = new BoxAPIConnection(DEVELOPER_TOKEN); BoxUser.Info userInfo = BoxUser.getCurrentUser(api).getInfo(); System.out.format("Welcome, %s <%s>!\n\n", userInfo.getName(), userInfo.getLogin()); fileById(api, FILE_ID); folderById(api, FOLDER_ID); } private static void folderById(BoxAPIConnection api, String folderId) { BoxFolder folder = new BoxFolder(api, folderId); BoxFolder.Info folderInfo = folder.getInfo(); System.out.format("folder with name (%s), parent name (%s) and id (%s)\n\n", folderInfo.getName(), folderInfo.getParent().getName(), folderInfo.getID()); } private static void fileById(BoxAPIConnection api, String fileId) { BoxFile file = new BoxFile(api, fileId); BoxFile.Info fileInfo = file.getInfo(); System.out.format("file with name (%s), parent name (%s) and id (%s)\n\n", fileInfo.getName(), fileInfo.getParent().getName(), fileInfo.getID()); } // the ouputs with the developer token //file with name (pic_caterpillar_gc45k_(0)_at87a31501.jpg), parent name (CATERPILLAR GC45K-LP-SWB100F-FPB-B154-AT87A315011274654-1R0) and id (19***phone number removed for privacy***) //folder with name (CATERPILLAR GC45K-LP-SWB100F-FPB-B154-AT87A315011274654-1R0), parent name (Assets) and id (***number removed for privacy***37) // part with the app user public static void main(String[] args) { // Turn off logging to prevent polluting the output. Logger.getLogger("com.box.sdk").setLevel(Level.OFF); folderById(FOLDER_ID); } private static BoxUser.Info createAppUser() { BoxAPIConnection adminConnection = adminBoxConnection(); CreateUserParams params = new CreateUserParams(); params.setIsPlatformAccessOnly(true); BoxUser.Info user = BoxUser.createAppUser(adminConnection, APP_USER_NAME, params); System.out.format("User created with name %s and id %s\n\n", APP_USER_NAME, user.getID()); return user; } private static void folderById(String folderId) { BoxAPIConnection userConnection = userBoxConnection(appUserId); BoxFolder folder = new BoxFolder(userConnection, folderId); BoxFolder.Info folderInfo = folder.getInfo(); System.out.format("folder with name (%s), parent name (%s) and id (%s)\n\n", folderInfo.getName(), folderInfo.getParent().getName(), folderInfo.getID()); } private static BoxDeveloperEditionAPIConnection userBoxConnection(String userId) { return BoxDeveloperEditionAPIConnection.getAppUserConnection(userId, clientId, clientSecret, jwtEncrptionPrferences(), accessTokenCache); } // outputs with the app user Exception in thread "main" com.box.sdk.BoxAPIException: The API returned an error code: 404 {"type":"error","status":404,"code":"not_found","context_info":{"errors":[{"reason":"invalid_parameter","name":"item","message":"Invalid value 'd_31997050337'. 'item' with value 'd_31997050337' not found"}]},"help_url":"http:\/\/developers.box.com\/docs\/#errors","message":"Not Found","request_id":"***number removed for privacy***159663d44a5452"} at com.box.sdk.BoxAPIResponse.(BoxAPIResponse.java:70) at com.box.sdk.BoxJSONResponse.(BoxJSONResponse.java:30) at com.box.sdk.BoxAPIRequest.trySend(BoxAPIRequest.java:435) at com.box.sdk.BoxAPIRequest.send(BoxAPIRequest.java:221) at com.box.sdk.BoxAPIRequest.send(BoxAPIRequest.java:196) at com.box.sdk.BoxFolder.getInfo(BoxFolder.java:253) at com.box.sdk.example.MainConnellJwtEnterprise.folderById(MainConnellJwtEnterprise.java:43) at com.box.sdk.example.MainConnellJwtEnterprise.main(MainConnellJwtEnterprise.java:37)
Thanks.
-
Hello ,
thank your first for your answer.
I am not admin on that folder because it belongs to a partner company.
Like mentioned the APP-USER was created programmatically to shortcutting the configuration in the UI.
So the APP-User is not manually invited. Could I do it for a such folder programmatically?
I have also another question concerning JWT and OAuth2 because i use it:
1- What is the difference between the ENTERPRISE-TOKEN and APP-USER-TOKEN?
2- What token should be used in this case for accessing the collaborated folder?
Kind Regards
-
Good morning ,
yesterday I answered your message but you deleted one of the two repeated messages so the forum gave an error and my answer was lost hehehe and to be sincere, I thought to do it again but yesterday flew... so, today trying again.
App-users can be created and assigned as collaborators through the API but will depend also on the permissions that the application / service account has. Also, you could do the other way around. Create folders with the service account or the app-users and invite the managed users to there.
About the other two questions (yesterday were three, weren't they? :))
1- This is a very common question and it is related to this thread: https://community.box.com/t5/Box-Developer-Forum/quot-Service-account-quot-vs-quot-app-user-quot/m-p/38592#M2557. Enterprise-token is a token using the service account and the app-user-token is using regular app-users.
2 - The answer is an ambigous "it depends" 🙂 I mean... the service account is like the "father" or "mother" of all the app-users created on that application. So, I would use that account (enterprise-token) as a powerful resource for administrative tasks (if any), maybe ownership of created folders within the application and in case that only one single user is enough for you. If you want / need to have several app-users due to limit api calls, one to one mapping with real users or something like that, then the token to be used is the app-user-token.
Hope this time arrives 🙂 and more important helps!
Regards
サインインしてコメントを残してください。
コメント
3件のコメント