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

Unable to upload a file to the right user

Answered
New post

Comments

3 comments

  • jcleblanc

    Hi ,

     

    This is related to how JWT apps structure users. By default when you create a JWT app there is a programmatic user created to represent that app, which is called a service account. When you go through the JWT / OAuth 2 process and don't specify a specific user all file uploads will go directly into that service account. Let me show you how to swap this with some Java samples.

     

    Let's say you go through the JWT auth process with the config file, obtained when you created your app, it may look something like this:

     

    Reader reader = new FileReader(Config.config_path);
    BoxConfig boxConfig = BoxConfig.readFrom(reader);
    		
    // Set cache info
    int MAX_CACHE_ENTRIES = 100;
    IAccessTokenCache accessTokenCache = new InMemoryLRUAccessTokenCache(MAX_CACHE_ENTRIES);
    
    // Create new app enterprise connection object
    BoxDeveloperEditionAPIConnection client = BoxDeveloperEditionAPIConnection.getAppEnterpriseConnection(boxConfig, accessTokenCache);

     

    The client variable will now reference the service account. This is what you're currently seeing. To instead set up that client variable to reference a user, replace that last line for client with something like this:

     

    String userId = "14542659";
    BoxDeveloperEditionAPIConnection client = new BoxDeveloperEditionAPIConnection(userId, DeveloperEditionEntityType.USER, boxConfig, accessTokenCache);

     

    Each of the SDKs have a method for doing this, and if you want the specific code sample in your SDK language (if Java is not what you're using) just let me know and I can provide it. 

     

    You'll just need a few things to make this happen:

    1. The user ID that you want to upload the file to.
    2. The right settings in your app to access and make calls on behalf of users. Take a look at this guide that covers all of that (and how to set it) in your app. You'll need to have the "Users" scope set in your app configuration, set "Application Access" to enterprise, and under "Advanced Features" select the option for "Generate User Access Tokens". The guide will provide you with those details as well.

    Please let me know if there are any issues that pop up.

     

    - Jon

    0
    Comment actions Permalink
  • Anthony-Gregg

    Jon,

     

    Thank you so much for this detailed answer. Yes, we are doing this in C# (.NET) but we definitely get the "gist" of what you are explaining and I think you have given us everything we need to at least make an attempt at retrying this and being able to move forward again ... 🙂

     

    Given the steps you have laid out and directions, we will try your suggested steps to get this working and if we run into further problems, I will reach out again.

     

    Thanks again Jon

    Anthony

    0
    Comment actions Permalink
  • KeithF11381

    I think I am experiencing the same thing.

     

    Question I have is what is the userid? It doesnt look like it is email address. Where do you get that information?

    0
    Comment actions Permalink

Please sign in to leave a comment.