Users represent an individual's account on Box.
- Get the Current User's Information
- Create An Enterprise User
- Create An App User
- Update User
- Delete User
- Invite User
- Get Email Aliases
- Add Email Alias
- Delete Email Alias
- Get Enterprise Users
- Get Enterprise Users (Marker Pagination)
- Get App Users By External App User ID
- Get App Users By External App User ID (Marker Pagination)
- Move User's Folder
To get the current user, call the static
getCurrentUser(BoxAPIConnection api)
method.
Then use getInfo(String... fields)
to get information about the user.
BoxUser user = BoxUser.getCurrentUser(api);
BoxUser.Info info = user.getInfo();
To get information about a user, call the getInfo()
method on the user object.
String userID = "33333";
BoxUser user = new BoxUser(api, userID);
BoxUser.Info userInfo = user.getInfo();
To retrieve the avatar for a user, call the getAvatar()
method on the user object.
String userID = "33333";
BoxUser user = new BoxUser(api, userID);
InputStream avatarStream = user.getAvatar();
To create an enterprise user, call the
createEnterpriseUser(BoxAPIConnection api, String loginEmail, String userName)
.
To pass additional optional parameters, use the
createEnterpriseUser(BoxAPIConnection api, String loginEmail, String userName, CreateUserParams options)
method.
BoxUser.Info createdUserInfo = BoxUser.createEnterpriseUser(api, "[email protected]", "A User");
To create an app user, call the
createAppUser(BoxAPIConnection api, String userName)
method.
To pass additional optional parameters, use the
createAppUser(BoxAPIConnection api, String userName, CreateUserParams options)
method.
BoxUser.Info createdUserInfo = BoxUser.createAppUser(api, "A User");
CreateUserParams params = new CreateUserParams();
params.setExternalAppUserId("An Identifier Like Login");
BoxUser.Info createdUserInfo = BoxUser.createAppUser(api, "A User", params);
To update a user call the updateInfo(BoxUser.Info fieldsToUpdate)
method.
BoxUser user = new BoxUser(api, "0");
BoxUser.Info info = user.new Info();
info.setName(name);
user.updateInfo(info);
To delete a user call the delete(boolean notifyUser, boolean force)
method.
The notifyUser
determines whether the user should receive an email about the deletion,
and the force
parameter will cause the user to be deleted even if they still have files
in their account.
BoxUser user = new BoxUser(api, "0");
user.delete(false, false);
To invite an existing user to join an Enterprise call the
inviteUser(String enterpriseID, String userEmail)
method.
BoxUser user = new BoxUser(api, "0");
user.invite("Enterprise ID", "Invited User Login");
To get a user's email aliases call the getEmailAliases()
method.
BoxUser user = new BoxUser(api, "0");
Collection<EmailAlias> emailAliases = user.getEmailAliases();
To add an email alias for a user, call the
addEmailAlias(String emailAddress)
method.
BoxUser user = new BoxUser(api, "0");
user.addEmailAlias("[email protected]");
Enterprise admins can automatically confirm the new email alias by calling the
addEmailAlias(String emailAddress, boolean confirm)
method:
BoxUser user = new BoxUser(api, "0");
user.addEmailAlias("[email protected]", true);
To delete a users email alias call the
deleteEmailAlias(String emailAliasID)
method.
BoxUser user = new BoxUser(api, "0");
user.deleteEmailAlias("123");
To get an enterprise's users call the
getAllEnterpriseUsers(BoxAPIConnection api)
,
getAllEnterpriseUsers(BoxAPIConnection api, String filterTerm, String... fields)
, or
getAllEnterpriseOrExternalUsers(BoxAPIConnection api, String filterTerm, String... fields)
method.
Iterable<BoxUser.Info> users = BoxUser.getAllEnterpriseUsers(api);
To get a list of all users in an enterprise, call the
getAllEnterpriseUsers(BoxAPIConnection api, boolean usemarker, String marker)
,
getAllEnterpriseUsers(BoxAPIConnection api, String filterTerm, boolean usemarker, String marker, String... fields)
, or
getAllEnterpriseOrExternalUsers(BoxAPIConnection api, String filterTerm, boolean usemarker, String marker, String... fields)
method.
To get a list of users starting from the first page of results, set the usemarker
parameter as true
and the marker
parameter as null
. If you would like to get the marker for the next page of results from the page the iterator is currently on, you must cast the iterable to BoxResourseIterable<BoxUser.info>
and call getNextMarker()
on that iterable. For more information on marker pagination, look here: https://developer.box.com/en/guides/api-calls/pagination/marker-based/.
Iterable<BoxUser.Info> users = BoxUser.getAllEnterpriseUsers(api, true, null);
// Get marker
String marker = ((BoxResourceIterable<BoxUser.Info>) users).getNextMarker();
To get app user using external app user ID, call the
getAppUsersByExternalAppUserID(BoxAPIConnection api, String externalID, String... fields)
.
This method allows you to easily associate Box app users with your application's
identifiers for those users.
Iterable<BoxUser.Info> users = BoxUser.getAppUsersByExternalAppUserID(api, "external_app_user_id");
To get app user using external app user ID, call the
getAppUsersByExternalAppUserID(BoxAPIConnection api, String externalID, boolean usemarker, String marker, String... fields)
.
This method allows you to easily associate Box app users with your application's
identifiers for those users. To get a list of users starting from the first page of results, set the usemarker
parameter as true
and the marker
parameter as null
. If you would like to get the marker for the next page of results from the page the iterator is currently on, you must cast the iterable to BoxResourseIterable<BoxUser.info>
and call getNextMarker()
on that iterable. For more information on marker pagination, look here: https://developer.box.com/en/guides/api-calls/pagination/marker-based/.
Iterable<BoxUser.Info> users = BoxUser.getAppUsersByExternalAppUserID(api, "external_app_user_id");
// Get marker
String marker = ((BoxResourceIterable<BoxUser.Info>) users).getNextMarker();
To move all of a user's content to another user, call the
transferContent(String destinationUserID)
method.
String sourceUserID = "11111";
String destinationUserID = "22222";
BoxUser sourceUser = new BoxUser(api, sourceUserID);
BoxFolder.Info transferredFolderInfo = sourceUser.transferContent(destinationUserID);