Skip to main content
Question

Enable an INACTIVE user via JAVA SDK

  • May 22, 2025
  • 7 replies
  • 25 views

Forum|alt.badge.img

I created a snippet to update the status of a user:

    public static boolean updateUserStatus(String uid, String status) throws IOException {
        BoxUser user = new BoxUser(api, uid);
        BoxUser.Info info = user.new Info();
        info.setStatus(BoxUser.Status.valueOf(status));

        user.updateInfo(info);
        return true;
    }

I was able to set the user's status to INACTIVE but I am unable to set it back again to ACTIVE because it won't allow the user to login when its already in INACTIVE state. I had to manually set from the console.

 

Is there a way for me to set an INACTIVE user to another status programmatically?

7 replies

Forum|alt.badge.img

Hi ,

 

 

Thanks for your post in the developer forum!

 

I think you may be right, given that the inactive user cannot "login". Have you checked the API docs here?

https://developer.box.com/reference

 

Hopefully others in the forum can help clarify!

 


Forum|alt.badge.img

 I just tested this with the cURL commands below. The API is working as expected. I was able to set an active user to inactive and then back to active.

  

#Check user status
curl "https://api.box.com/2.0/users/USER_ID?fields=status" \ -H "Authorization: Bearer ACCESS_TOKEN"
#Set user to inactive curl https://api.box.com/2.0/users/USER_ID \ -H "Authorization: Bearer ACCESS_TOKEN" \ -d '{"status": "inactive"}' \ -X PUT
#Check user status curl "https://api.box.com/2.0/users/USER_ID?fields=status" \ -H "Authorization: Bearer ACCESS_TOKEN"
#Set user to active curl https://api.box.com/2.0/users/USER_ID \ -H "Authorization: Bearer ACCESS_TOKEN" \ -d '{"status": "active"}' \ -X PUT

#Check user status
curl "https://api.box.com/2.0/users/USER_ID?fields=status" \
-H "Authorization: Bearer ACCESS_TOKEN"

 

With the Java SDK, you can set a user's status back to active using the same setStatus method you used to set the user to inactive.

 

BoxUser user = new BoxUser(api, "0");
BoxUser.Info info = user.new Info();
info.setStatus("active");
user.updateInfo(info);

 

Are you running into any errors when using the setStatus method to set the user back to active status?


Forum|alt.badge.img

Thanks Murtza, given your java code above, that's my code I posted above. I just replaced the "0" with the userId. OI was able to set a user's status to INACTIVE but once inactive, I can't set its status to ACTIVE unless I go to the Box website and set it manually. I was hoping I could do that programmatically.


I'll check mimicking the curl command via java or maybe I'm missing something on the SDK. Or should I really set it to "0" rather than the userId?


Forum|alt.badge.img

Hi Howard,

 

I checked but I can't find one to solve it.


Forum|alt.badge.img

 When you make the request to set the user to active with the API, can you please share response you get back? 


Forum|alt.badge.img

Get an admin api object

 

Iterable users = BoxUser.getAllEnterpriseUsers(adminApi);

 

Iterate through the users returned from the above call, when u find the user you are trying to activate do the following

 

inf.setStatus(Status.ACTIVE);

inf.getResource().updateInfo(inf);

 

Works for me.


Forum|alt.badge.img

Hi Mustza,

 

Thanks you for always responding to my queries.

 

Sorry, my bad. Was away for a awhile. I just rechecked the code, twas a mistake on my part. Snippet above taken from the SDK sample works. Its just that I was trying to get the user's info first before activating it, which is not possbile because the account is inactive. Sorry for the ruckus.

 

patingsadagat