AdminUsersResource
This class is used to send requests to Admin User API Routes. All its method
are available in the JS Client under the medusa.admin.users
property.
All methods in this class require user authentication.
A store can have more than one user, each having the same privileges. Admins can manage users, their passwords, and more.
Related Guide: How to manage users.
Methods
create
Create an admin user. The user has the same privileges as all admin users, and will be able to authenticate and perform admin functionalities right after creation.
Example
Parameters
customHeaders
Record<string, any>RequiredDefault: {}
Returns
Resolves to the user's details.
delete
Delete a user. Once deleted, the user will not be able to authenticate or perform admin functionalities.
Example
Parameters
id
stringRequiredcustomHeaders
Record<string, any>RequiredDefault: {}
Returns
Resolves to the deletion operation's details.
list
Retrieve all admin users.
Example
Parameters
customHeaders
Record<string, any>RequiredDefault: {}
Returns
Resolves to the list of users.
resetPassword
Reset the password of an admin user using their reset password token. You must generate a reset password token first for the user using the sendResetPasswordToken method, then use that token to reset the password in this method.
Example
Parameters
The reset details.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
Resolves to the user's details.
retrieve
Retrieve an admin user's details.
Example
Parameters
id
stringRequiredcustomHeaders
Record<string, any>RequiredDefault: {}
Returns
Resolves to the user's details.
sendResetPasswordToken
Generate a password token for an admin user with a given email. This also triggers the user.password_reset
event. So, if you have a Notification Service installed
that can handle this event, a notification, such as an email, will be sent to the user. The token is triggered as part of the user.password_reset
event's payload.
That token must be used later to reset the password using the resetPassword method.
Example
import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.users
.sendResetPasswordToken({
email: "user@example.com",
})
.then(() => {
// successful
})
.catch(() => {
// error occurred
})
Parameters
The user's reset details.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
update
Update an admin user's details.
Example
Parameters
id
stringRequiredThe attributes to update in the user.
customHeaders
Record<string, any>RequiredDefault: {}