Users

Here is a list of methods and examples of working with Users

Get All

// execute request users without credentials - returns only you
var users = await client.Users.GetAllAsync();

// send credentials - list of all users
var users = await client.Users.GetAllAsync(useAuth:true);

Get By ID

// returns user by ID
var user = await client.Users.GetByIDAsync(123);

Get Current User

// returns current user
var user = await client.Users.GetCurrentUserAsync();

Query

Create parametrized request

// returns result of query
var queryBuilder = new UsersQueryBuilder();
queryBuilder.PerPage = 40;
queryBuilder.Page = 2;
queryBuilder.Before = DateTime.Now;
var users = await client.Users.QueryAsync(queryBuilder);

Query with Roles

To retreive users with roles, you'll need to set the Context property of the UsersQueryBuilder to Context.Edit.

UsersQueryBuilder queryBuilder = new()
{
    // required for roles to be loaded
    Context = Context.Edit
};

List<User> users = await _clientAuth.Users.QueryAsync(queryBuilder, true);

Create new User

// returns created user
var user = new User("username","email","password")
{
    NickName= "nickname"
};
if (await client.IsValidJWTokenAsync())
{
    var user = await client.Users.CreateAsync(user);
}

Update User

// returns updated user
var user = client.Users.GetByIDAsync(123);
user.Name = "New Name";
if (await client.IsValidJWTokenAsync())
{
    var updatedUser = await client.Users.UpdateAsync(user);
}

Delete User

// returns result of deletion
if (await client.IsValidJWTokenAsync())
{
    //second param - user to reassign all content
    var result = await client.Users.DeleteAsync(123,321);
}

Create Application Password

// Create an application password for the current user
var password = await client.Users.CreateApplicationPasswordAsync("application-name");

// Create an application password for a specific user
var password = await client.Users.CreateApplicationPasswordAsync("application-name", userId: "3");