Skip to main content
Question

CreateAppUser returns 400

  • May 21, 2025
  • 16 replies
  • 19 views

Forum|alt.badge.img

hi all, 

 

Do you know why CreateAppUser.java returns 400?.  I already setup and install RSA public key into my Box application and here is my variable setting

 

private static final String CLIENT_ID = "XXXX";
private static final String CLIENT_SECRET = "XXXXX";
private static final String ENTERPRISE_ID = "MYID";
private static final String PUBLIC_KEY_ID = "XXXX";
private static final String PRIVATE_KEY_FILE = "C:\\pem\\private_key.box.pem";
private static final String PRIVATE_KEY_PASSWORD = "XXXXX";
private static final String APP_USER_NAME = "fusion";
private static final int MAX_CACHE_ENTRIES = 100;

16 replies

Forum|alt.badge.img

Can you share the stacktrace?


Forum|alt.badge.img

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)


Forum|alt.badge.img

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

BOX_2pr59ntijjvrp4r1y77wp62t7wzj6zwp.png


Forum|alt.badge.img

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)

 

BOX_65bzumar383ny6cq19o1m82srb23t8gv.png


Forum|alt.badge.img

Forum|alt.badge.img

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?


Forum|alt.badge.img

I believe that's it! 


Forum|alt.badge.img

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? 

Forum|alt.badge.img

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

BOX_kzliguptptoza0d402a8d5x3ag4npqp7.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.


Forum|alt.badge.img

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)


Forum|alt.badge.img

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.


Forum|alt.badge.img

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


Forum|alt.badge.img

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
            }
        }

Forum|alt.badge.img

I'll start adding JWT examples here:

https://github.com/kendomen/BoxJavaJWTExamples

 

 


Forum|alt.badge.img

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)


Forum|alt.badge.img

Can you set a breakpoint on BoxDeveloperEditionAPIConnection.java?

 

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

 

BOX_5wf4e7dvv0gnc0r2irjbgdurh3ven5pw.png