Users represent an individual's account on Box.
- Get the Current User's Information
- Get User's Information
- Get User Avatar
- Add or update User Avatar
- Delete User Avatar
- Add New User
- Add New App User
- Update User
- Delete User
- Get Email Aliases
- Add Email Alias
- Delete Email Alias
- Get Enterprise Users
- Transfer User Content
To get the current user call the UsersManager.GetCurrentUserInformationAsync(IEnumerable<string> fields = null)
method.
BoxUser currentUser = await client.UsersManager.GetCurrentUserInformationAsync();
To get a user call UsersManager.GetUserInformationAsync(string userId)
with the ID of the user.
BoxUser user = await client.UsersManager.GetUserInformationAsync(userId: "33333");
To retrieve the avatar image for a user, call
UsersManager.GetUserAvatar(string userId)
with the ID of the user.
Stream imageStream = await client.UsersManager.GetUserAvatar(string userId);
To add or update user avatar call the
UsersManager.AddOrUpdateUserAvatarAsync(string userId, FileStream stream)
method with the ID of the user and and a fileStream of the avatar contents to upload.
using (FileStream fileStream = new FileStream(filePath, FileMode.Open))
{
BoxUploadAvatarResponse response = await client.UsersManager.AddOrUpdateUserAvatarAsync(userId, fileStream);
}
Alternatively, you can use a generic stream (e.g. MemoryStream) and provide filename explicitly. The filename should also contain file extension (.jpg or .png).
Stream genericStream;
BoxUploadAvatarResponse response = await client.UsersManager.AddOrUpdateUserAvatarAsync(userId, genericStream, "avatar.png");
To remove existing user avatar call the
UsersManager.DeleteUserAvatarAsync(string userId)
method with the ID of the user.
bool isDeleted = await client.UsersManager.DeleteUserAvatarAsync(userId);
To provision a new managed user within the current enterprise, call the
UsersManager.CreateEnterpriseUserAsync(BoxUserRequest userRequest, IEnumerable<string> fields = null)
method with the email address the user will use to log in and the user's name.
var userParams = new BoxUserRequest()
{
Name = "Example User",
Login = "[email protected]"
};
BoxUser newUser = await client.UsersManager.CreateEnterpriseUserAsync(userParams);
To provision a new app user within the current enterprise, call the
UsersManager.CreateEnterpriseUserAsync(BoxUserRequest userRequest, IEnumerable<string> fields = null)
method with the BoxUserRequest.IsPlatformAccessOnly
property set to true
.
var userParams = new BoxUserRequest()
{
Name = "App User 12",
ExternalAppUserId = "external-id",
IsPlatformAccessOnly = true
};
BoxUser newUser = await client.UsersManager.CreateEnterpriseUserAsync(userParams);
To update a user's information, call
UsersManager.UpdateUserInformationAsync(BoxUserRequest userRequest, IEnumerable<string> fields = null)
with the fields to update.
var updates = new BoxUserRequest()
{
Id = "44444",
Role = "coadmin",
CanSeeManagedUsers = true
};
BoxUser updatedUser = await client.UsersManager.UpdateUserInformationAsync(updates);
To delete a user call the
UsersManager.DeleteEnterpriseUserAsync(string userId, bool notify, bool force)
method. If the user still has files in their account and the force
parameter
is not sent, an error is returned.
await client.UsersManager.DeleteEnterpriseUserAsync("44444", notify: false, force: true);
To get a users email aliases, call UsersManager.GetEmailAliasesAsync(string userId)
with the ID of the user.
BoxCollection<BoxEmailAlias> aliases = await client.UsersManager
.GetEmailAliasesAsync(userId: "33333");
To add an email alias for a user, call UsersManager.AddEmailAliasAsync(string userId, string email)
with the ID of the user and the email address to add as an alias.
BoxEmailAlias alias = await client.UsersManager
.AddEmailAliasAsync(userId: "33333", email: "[email protected]");
To delete a users email alias, call UsersManager.DeleteEmailAliasAsync(string userId, string emailAliasId)
with the ID of the user to whom the alias belongs and the ID of the email alias.
await client.UsersManager.DeleteEmailAliasAsync(userId: "33333", emailAliasId: "12345");
Get a list of users in the current enterprise by calling the
UsersManager.GetEnterpriseUsersAsync(string filterTerm = null, uint offset = 0, uint limit = 100, IEnumerable<string> fields = null, string userType = null, string externalAppUserId = null, bool autoPaginate = false)
method.
BoxCollection<BoxUser> users = await client.UsersManager.GetEnterpriseUsersAsync();
To transfer one managed user's content to another user's account, call the
MoveUserFolderAsync(string userId, string ownedByUserId, string folderId = "0", bool notify = false)
method with the IDs of the source and destination users.
Note: Currently, only moving the user's root folder (with ID "0") is supported.
var sourceUserId = "33333";
var destinationUserId = "44444";
BoxFolder movedFolder = await client.MoveUserFolderAsync(sourceUserId, destinationUserId);