Users represent an individual's account on Box.
- Get the Current User's Information
- Get User Information
- Get Avatar for a User
- Add or update user avatar
- Delete user avatar
- 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 downloadAvatar(OutputStream stream)
method on the user object.
String userID = "33333";
// some stream do download avatar
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()){
BoxUser user=new BoxUser(api,userID);
user.downloadAvatar(outputStream);
} catch (IOException e) {
throw new RuntimeException(e);
}
To add or update the avatar for a User, call the uploadAvatar(File)
method on the user object.
String userID = "33333";
BoxUser user = new BoxUser(api, userID);
AvatarUploadResponse response = user.uploadAvatar(new File("path_to_avatar_file"));
In return, you will get an object with links to several representations of an avatar within Box account. Your image file should have correct extension, it is used to determine image type used in upload. Supported formats are JPG and PNG. The image size cannot exceed 1024 * 1024 pixels or 1MB.
You can upload avatart using InputStream
with uploadAvatar(InputStream, String)
:
String userID = "33333";
BoxUser user = new BoxUser(api, userID);
AvatarUploadResponse response = user.uploadAvatar(Files.newInputStream(Paths.get("path_to_avatar_file")), "file_name.jpeg");
Both upload methods supports ProgressListener
.
To delete User avatar image use deleteAvatar()
method on the user object:
String userID = "33333";
BoxUser user = new BoxUser(api, userID);
user.deleteAvatar();
To create an enterprise user, call the
createEnterpriseUser(BoxAPIConnection api, String loginEmail, String userName, String... fields)
.
To pass additional optional parameters, use the
createEnterpriseUser(BoxAPIConnection api, String loginEmail, String userName, CreateUserParams options, String... fields)
method.
BoxUser.Info createdUserInfo = BoxUser.createEnterpriseUser(api, "[email protected]", "A User");
To create an app user, call the
createAppUser(BoxAPIConnection api, String userName, String... fields)
method.
To pass additional optional parameters, use the
createAppUser(BoxAPIConnection api, String userName, CreateUserParams options, String... fields)
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, String... fields)
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 or one that
uses API default parameters `delete()
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);