Skip to content

Latest commit

 

History

History
321 lines (237 loc) · 14.6 KB

users.md

File metadata and controls

321 lines (237 loc) · 14.6 KB

Users

Users represent an individual's account on Box.

Get the Current User's Information

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();

Get User Information

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();

Get Avatar for a User

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

Add or update user avatar

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.

Delete user avatar

To delete User avatar image use deleteAvatar() method on the user object:

String userID = "33333";
BoxUser user = new BoxUser(api, userID);
user.deleteAvatar();

Create An Enterprise User

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, "user@example.com", "A User");

Create An App 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);

Update User

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);

Delete User

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);

Invite User

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");

Get Email Aliases

To get a user's email aliases call the getEmailAliases() method.

BoxUser user = new BoxUser(api, "0");
Collection<EmailAlias> emailAliases = user.getEmailAliases();

Add Email Alias

To add an email alias for a user, call the addEmailAlias(String emailAddress) method.

BoxUser user = new BoxUser(api, "0");
user.addEmailAlias("user+alias@example.com");

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("user+alias@eexample.com", true);

Delete Email Alias

To delete a users email alias call the deleteEmailAlias(String emailAliasID) method.

BoxUser user = new BoxUser(api, "0");
user.deleteEmailAlias("123");

Get Enterprise Users

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);

Get Enterprise Users (Marker Pagination)

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();

Get App Users By External App User ID

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");

Get App Users By External App User ID (Marker Pagination)

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();

Move User's Folder

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);