CreateAppUser returns 400

New post

Comments

16 comments

  • kendomen

    Can you share the stacktrace?

    0
    Comment actions Permalink
  • Khanh2

    thanks, stack trace is

     

    log4j:WARN No appenders could be found for logger (org.jose4j.jwa.AlgorithmFactoryFactory).
    log4j:WARN Please initialize the log4j system properly.
    log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
    Exception in thread "main" com.box.sdk.BoxAPIException: The API returned an error code: 400
    at com.box.sdk.BoxAPIResponse.(BoxAPIResponse.java:70)
    at com.box.sdk.BoxJSONResponse.(BoxJSONResponse.java:30)
    at com.box.sdk.BoxAPIRequest.trySend(BoxAPIRequest.java:423)
    at com.box.sdk.BoxAPIRequest.send(BoxAPIRequest.java:209)
    at com.box.sdk.BoxAPIRequest.send(BoxAPIRequest.java:184)
    at com.box.sdk.BoxDeveloperEditionAPIConnection.authenticate(BoxDeveloperEditionAPIConnection.java:245)
    at com.box.sdk.BoxDeveloperEditionAPIConnection.tryRestoreUsingAccessTokenCache(BoxDeveloperEditionAPIConnection.java:305)
    at com.box.sdk.BoxDeveloperEditionAPIConnection.getAppEnterpriseConnection(BoxDeveloperEditionAPIConnection.java:169)
    at com.wdc.box.tools.CreateAppUser.main(CreateAppUser.java:47)

    0
    Comment actions Permalink
  • kendomen

    So there error is on this line

    BoxDeveloperEditionAPIConnection api = BoxDeveloperEditionAPIConnection.getAppEnterpriseConnection(
                ENTERPRISE_ID, CLIENT_ID, CLIENT_SECRET, encryptionPref, accessTokenCache);

    So I'm wondering what scope you have set on the app

    scope.png

    0
    Comment actions Permalink
  • Khanh2

    I did the same as u did, but still the same error.

    does it matter that i'm not a box admin?  my account type is enterprise.  I used my id in the ENTERPRISE_ID

    Exception in thread "main" com.box.sdk.BoxAPIException: The API returned an error code: 400
    at com.box.sdk.BoxAPIResponse.(BoxAPIResponse.java:70)
    at com.box.sdk.BoxJSONResponse.(BoxJSONResponse.java:30)
    at com.box.sdk.BoxAPIRequest.trySend(BoxAPIRequest.java:423)
    at com.box.sdk.BoxAPIRequest.send(BoxAPIRequest.java:209)
    at com.box.sdk.BoxAPIRequest.send(BoxAPIRequest.java:184)
    at com.box.sdk.BoxDeveloperEditionAPIConnection.authenticate(BoxDeveloperEditionAPIConnection.java:245)
    at com.box.sdk.BoxDeveloperEditionAPIConnection.tryRestoreUsingAccessTokenCache(BoxDeveloperEditionAPIConnection.java:305)
    at com.box.sdk.BoxDeveloperEditionAPIConnection.getAppEnterpriseConnection(BoxDeveloperEditionAPIConnection.java:169)
    at com.wdc.box.tools.CreateAppUser.main(CreateAppUser.java:47)

     

    mtp.JPG

    0
    Comment actions Permalink
  • kendomen

    Did you grant access?

     

    https://docs.box.com/docs/app-auth#section-3-grant-access-in-enterprise-admin-console

     

     

     

    0
    Comment actions Permalink
  • Khanh2

    thanks Ken, not yet, i have to ask my box admin to do that.  

    is there any thing else need to be done after that?

    0
    Comment actions Permalink
  • kendomen

    I believe that's it! 

    0
    Comment actions Permalink
  • Khanh2

    Ken, i heard a service account will be created upon authorization.  

    1. how do i obtain that account since its a backend  account that my box admin has no ideas?
    2. what role does this service account play in creating app user?
    3. once app user is created, can i add it to any shared folder for collaboration through box web? 
    0
    Comment actions Permalink
  • kendomen

    1.  You can see the AppUser or ServiceAccount content through admin console -> content manager

    serviceaccount.png

    2.  The ServiceAccount creates the AppUser

    // 1.  I think this is the ServiceAccount
    BoxDeveloperEditionAPIConnection api = BoxDeveloperEditionAPIConnection.getAppEnterpriseConnection(
                ENTERPRISE_ID, CLIENT_ID, CLIENT_SECRET, encryptionPref, accessTokenCache);
    
    // 2. The AppUser is created here 
           CreateUserParams params = new CreateUserParams();
            params.setSpaceAmount(removed for privacy4); //1 GB
            BoxUser.Info user = BoxUser.createAppUser(api, APP_USER_NAME, params);

    3.  I believe you can do it programmatically but not through box web since AppUsers are hidden.

    0
    Comment actions Permalink
  • Khanh2

    my box admin said she has authorized my app, but i still have the same error.

    when she authorizes it, is there any thing she needs to give me? 

    do you know how to create app user via postman?

     

    log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
    Exception in thread "main" com.box.sdk.BoxAPIException: The API returned an error code: 400
    at com.box.sdk.BoxAPIResponse.(BoxAPIResponse.java:70)
    at com.box.sdk.BoxJSONResponse.(BoxJSONResponse.java:30)
    at com.box.sdk.BoxAPIRequest.trySend(BoxAPIRequest.java:423)
    at com.box.sdk.BoxAPIRequest.send(BoxAPIRequest.java:209)
    at com.box.sdk.BoxAPIRequest.send(BoxAPIRequest.java:184)
    at com.box.sdk.BoxDeveloperEditionAPIConnection.authenticate(BoxDeveloperEditionAPIConnection.java:245)
    at com.box.sdk.BoxDeveloperEditionAPIConnection.tryRestoreUsingAccessTokenCache(BoxDeveloperEditionAPIConnection.java:305)
    at com.box.sdk.BoxDeveloperEditionAPIConnection.getAppEnterpriseConnection(BoxDeveloperEditionAPIConnection.java:169)
    at com.wdc.box.tools.CreateAppUser.main(CreateAppUser.java:47)

    0
    Comment actions Permalink
  • kendomen

    I'm currently getting the same error now using box-java-sdk. 

    I have opened a ticket with Box to see what is happening.

    In the meantime, I'm trying out the Box .NET SDK.

    I'll keep you posted.

    0
    Comment actions Permalink
  • kendomen

    Ok, the call is working again.  Can you try it now and see if it works for you?

    0
    Comment actions Permalink
  • kendomen

    Working with support, this is what we've got working...

     

            BoxDeveloperEditionAPIConnection api = BoxDeveloperEditionAPIConnection.getAppEnterpriseConnection(
                    ENTERPRISE_ID, CLIENT_ID, CLIENT_SECRET, encryptionPref, accessTokenCache);
    
            BoxUser.Info userInfo = BoxUser.getCurrentUser(api).getInfo();
            System.out.format("Welcome, %s!\n\n", userInfo.getName());
    
            Iterable managedUsers = BoxUser.getAllEnterpriseUsers(api);  
            for (BoxUser.Info managedUser : managedUsers) {
                System.out.println(managedUser.getName() + " " + managedUser.getStatus());
                if (managedUser.getStatus().equals(BoxUser.Status.ACTIVE)) {
    
                    // used to get AppUser or ManagedUser
                    BoxDeveloperEditionAPIConnection userApi = BoxDeveloperEditionAPIConnection.getAppUserConnection(managedUser.getID(), CLIENT_ID, CLIENT_SECRET, encryptionPref, accessTokenCache);
    
                    BoxFolder boxFolder = BoxFolder.getRootFolder(userApi);
                    Iterable items = boxFolder.getChildren("name");
                    for (BoxItem.Info item : items) {
                        System.out.println("\t" + item.getName());
                    }
                    break;
                    // 400 means they haven't accepted TOC
                    // 403 means - inactive
                }
            }
    0
    Comment actions Permalink
  • kendomen

    I'll start adding JWT examples here:

    https://github.com/kendomen/BoxJavaJWTExamples

     

     

    0
    Comment actions Permalink
  • Khanh2

    thanks Ken for your very hard work.  but i still getting 400.

    is there any way for me to confirm that my box admin has authorized my app?  I'm skeptical that she did it now

    Exception in thread "main" com.box.sdk.BoxAPIException: The API returned an error code: 400
    at com.box.sdk.BoxAPIResponse.(BoxAPIResponse.java:70)
    at com.box.sdk.BoxJSONResponse.(BoxJSONResponse.java:30)
    at com.box.sdk.BoxAPIRequest.trySend(BoxAPIRequest.java:423)
    at com.box.sdk.BoxAPIRequest.send(BoxAPIRequest.java:209)
    at com.box.sdk.BoxAPIRequest.send(BoxAPIRequest.java:184)
    at com.box.sdk.BoxDeveloperEditionAPIConnection.authenticate(BoxDeveloperEditionAPIConnection.java:245)
    at com.box.sdk.BoxDeveloperEditionAPIConnection.tryRestoreUsingAccessTokenCache(BoxDeveloperEditionAPIConnection.java:305)
    at com.box.sdk.BoxDeveloperEditionAPIConnection.getAppEnterpriseConnection(BoxDeveloperEditionAPIConnection.java:169)
    at com.wdc.box.tools.CreateAppUser.main(CreateAppUser.java:60)

    0
    Comment actions Permalink
  • kendomen

    Can you set a breakpoint on BoxDeveloperEditionAPIConnection.java?

     

    I set a breakpoint there and captured the post & urlParamters and ran it through Postman.

     

    postman.png

    0
    Comment actions Permalink

Please sign in to leave a comment.