App Users created from .Net SDK cannot see folders or files - but they are there...
I have the following console application code and I'm seeing that with the developer token I can see all files and folders. But the App Users that I create cannot see anything. Anyone have a sample that downloads a file using the .Net SDK?
Do I need to create a user manually and assign permissions? I've seen alot of the same problems in other posts but I've not seen a solution yet...
Code:
try { // from https://github.com/box/box-windows-sdk-v2 var config = ConfigureBoxApi(); var boxJWT = new BoxJWTAuth(config); // create a Admin Client with permissions to manage app users var adminToken = boxJWT.AdminToken(); var adminClient = boxJWT.AdminClient(adminToken); // Create an App User var userRequest = new BoxUserRequest() { Name = "test appuser", IsPlatformAccessOnly = true }; var appUser = await adminClient.UsersManager.CreateEnterpriseUserAsync(userRequest); Console.WriteLine("New app user created with Id = {0}", appUser.Id); // user client with access to user's data (folders, files, etc) string appUserToken = boxJWT.UserToken(appUser.Id); //valid for 60 minutes so should be cached and re-used var appUserClient = boxJWT.UserClient(appUserToken, appUser.Id); // Root folder shows Zero child items with the created appUser????? var boxRootFolderItems = await appUserClient.FoldersManager.GetInformationAsync("0"); List boxFolderItemsList = boxRootFolderItems.Entries; foreach (BoxItem item in boxFolderItemsList) { // Nothing? ... Console.WriteLine("Item Name: {0}. Item Id: {1}", item.Name, item.Id); } } catch (Box.V2.Exceptions.BoxException boxEx) { Console.Write(boxEx.Message); }
-
Good afternoon ,
as per the script you've enclosed I can see you are creating an APP User and try to use it immediately to recover documents but that user has not uploaded anything at all.
In case that you want the APPUser to be able to see documents that belong to you (or to any user btw) you need to invite them as collaborators for a specific folder as you would do with any other user.
Regards
-
Good morning ,
to do the first test I would avoid API and do the PoC manually. The user you have created is now on your box instance. You can go to your admin console and see the user there.
Add the user to any folder as viewer, editor, whatever, and then run again the piece of script that returns the children of the shared folder. You will see that then you will see certain documents.
Remember that the developer token use your user as the one login, that's the reason you see all your documents.
If you use the service account created with the application or any app user newly created they will only see their own documents.
At API level you have to use the collaboration endpoint: https://developer.box.com/reference#collaboration-object
This endpoint allows you to share documents and folders, but thing that you can share the content where you are editor or (co)owner. So, you can test it with two different app users. With APPUSER1 create some documents and upload a couple of folders. If you try at this point with APPUSER2 to access those documents you won't see them. So, with APPUSER1 again create a collaboration element adding APPUSER2 with any role (but uploader) and you will be able to see the documents on the shared folder.
Hope this helps you.
Please sign in to leave a comment.
Comments
3 comments