Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I have followed the steps in .NET SDK documenation for JWT authenticated app, but keep getting empty items collection on GetFolderItemsAsync method.

I have configured it with Enterprise application access and authorized it...

Authentication seems ok, because I don't get an exception when creating the BoxJWTAuth object.

        var reader = new StreamReader(@"PathToJSONConfigFile");
        var json = reader
            .ReadToEnd();
        var config = BoxConfig
            .CreateFromJsonString(json);
        var sdk = new BoxJWTAuth(config);
        var token = sdk
            .AdminToken();
        var adminClient = sdk
            .AdminClient(token);
        var folders = await adminClient
            .FoldersManager
            .GetFolderItemsAsync("0", 500, fields: new string[] { BoxCollection.FieldEntries });

Figured it out on my own.

Just in case somebody faces the same problem. I was trying to access folders with a automatically generated admin client. Apparently this type of client doesn't have authorization to get folder lists.

You have to get your enterprise users and instantiate a user client object with user id.

var boxUsers = await adminClient.UsersManager.GetEnterpriseUsersAsync();
        var user= boxUsers
            .Entries
            .FirstOrDefault(x => x.Login.Contains("user"));
        var cli = new BoxClient(config, auth, asUser: user.Id);
            var fold = await cli
            .FoldersManager
            .GetFolderItemsAsync("0", 500, fields: new string[] { BoxCollection.FieldEntries, BoxItem.FieldName, BoxItem.FieldSharedLink, BoxItem.FieldPathCollection });
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.