Welcome to the new Box Support website. Check out all the details here on what’s changed.

Enable an INACTIVE user via JAVA SDK

New post

Comments

7 comments

  • Howard

    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!

     

    0
    Comment actions Permalink
  • Murtza

     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?

    0
    Comment actions Permalink
  • patingsadagat

    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?

    0
    Comment actions Permalink
  • patingsadagat

    Hi Howard,

     

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

    0
    Comment actions Permalink
  • Murtza

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

    0
    Comment actions Permalink
  • abhir

    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.

    0
    Comment actions Permalink
  • patingsadagat

    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

    0
    Comment actions Permalink

Please sign in to leave a comment.