Skip to content

Latest commit

 

History

History
218 lines (168 loc) · 6.66 KB

users.md

File metadata and controls

218 lines (168 loc) · 6.66 KB

Users

Users represent an individual's account on Box.

Get the Current User's Information

To get the current user call the UsersManager.GetCurrentUserInformationAsync(IEnumerable<string> fields = null) method.

BoxUser currentUser = await client.UsersManager.GetCurrentUserInformationAsync();

Get User's Information

To get a user call UsersManager.GetUserInformationAsync(string userId) with the ID of the user.

BoxUser user = await client.UsersManager.GetUserInformationAsync(userId: "33333");

Get User Avatar

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

Add or Update User Avatar

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

Delete User Avatar

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

Add New User

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

Add New App User

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

Update User

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

Delete User

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

Get Email Aliases

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

Add Email Alias

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

Delete Email Alias

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 Enterprise Users

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

Transfer User Content

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