👥Users

Learn how to add and edit users.

Get One User

To retrieve a single user, you can use the following API call:

const user_id = "<userid>";
wranglebot.query.users.one(user_id).fetch();

Replace <userid> with the ID of the user you want to retrieve.

Get Many Users

To retrieve multiple users based on a set of filters, use the following API call:

const filters = {
    $ids: ["<userid>"]
};
wranglebot.query.users.many(filters).fetch();

Replace <userid> with the ID(s) of the user(s) you want to retrieve. You can also specify other filters such as username or email.

Update One User

To update a user's information, use the following API call:

const user_id = "<userid>";
const changes = {
    email: "hello@example.com",
    password: "plaintext", 
    firstName: "Hans",
    lastName: "Dieter",
}
wranglebot.query.users.one(user_id).put(changes);

Replace <userid> with the ID of the user you want to update. You can update any of the user's fields, such as their email, password, first name, or last name. Note that the password must meet certain requirements.

Revoke User Access To Library

To revoke a user's access to a library, use the following API call:

const user_id = "<user_id>";
const library_id = "<library_id>";
await wranglebot.query.users.one(user_id).revoke(library_id);

Replace <user_id> with the ID of the user you want to revoke access from, and <library_id> with the ID of the library you want to revoke access to.

This feature will only work if the library is set to classified

Allow User Access to Library

To grant a user access to a library, use the following API call:

const user_id = "<user_id>";
const library_id = "<library_id>";
wranglebot.query.users.one(user_id).allow(library_id);

Replace <user_id> with the ID of the user you want to grant access to, and <library_id> with the ID of the library you want to grant access to.

Reset User Password

To reset a user's password, use the following API call:

const user_id = "<user_id>";
const newPassword = await wranglebot.query.users.one(user_id).reset();
console.log(newPassword) // the password

Replace <user_id> with the ID of the user whose password you want to reset. The new password will be returned as a string.

Add One User

To add a new user, use the following API call:

wranglebot.query.users.post({
	username: "my-user",  
	password: "plaintext",  
	email: "example@example.com",  
	roles: ["maintainer"],   
	firstName: "Henriette",  
	lastName: "Dietrichs"
});

You can specify the user's username, password, email, roles, first name, and last name. Once the user is added, the User will be returned as a reference.

Remove One User

Currently you can not delete a user via the API. To lock a user out, simply change the password.

Last updated