Skip to main content
Skip to main content
You're viewing the documentation for v1, which isn't the latest Medusa version.Latest documentation

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​

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.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns​

ResponsePromiseResponsePromise<void>Required
Resolves when the token is generated successfully.

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​

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.resetPassword({
token: "supersecrettoken",
password: "supersecret"
})
.then(({ user }) => {
console.log(user.id);
})

Parameters​

The reset details.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns​

ResponsePromiseResponsePromise<AdminUserRes>Required
Resolves to the user's details.

retrieve​

Retrieve an admin user's details.

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.retrieve(userId)
.then(({ user }) => {
console.log(user.id);
})

Parameters​

idstringRequired
The user's ID.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns​

ResponsePromiseResponsePromise<AdminUserRes>Required
Resolves to the user's details.

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​

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.create({
email: "user@example.com",
password: "supersecret"
})
.then(({ user }) => {
console.log(user.id);
})

Parameters​

payloadAdminCreateUserPayloadRequired
The user to create.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns​

ResponsePromiseResponsePromise<AdminUserRes>Required
Resolves to the user's details.

update​

Update an admin user's details.

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.update(userId, {
first_name: "Marcellus"
})
.then(({ user }) => {
console.log(user.id);
})

Parameters​

idstringRequired
The user's ID.
payloadAdminUpdateUserPayloadRequired
The attributes to update in the user.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns​

ResponsePromiseResponsePromise<AdminUserRes>Required
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​

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.delete(userId)
.then(({ id, object, deleted }) => {
console.log(id);
})

Parameters​

idstringRequired
The user's ID.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns​

ResponsePromiseResponsePromise<DeleteResponse>Required
Resolves to the deletion operation's details.

list​

Retrieve all admin users.

Example​

To list users:

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.list()
.then(({ users }) => {
console.log(users.length);
})

By default, only the first 20 users are returned. You can control pagination by specifying the limit and offset properties:

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.list({
limit,
offset
})
.then(({ users, limit, offset, count }) => {
console.log(users.length);
})

Parameters​

customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns​

ResponsePromiseResponsePromise<AdminUsersListRes>Required
Resolves to the list of users.
Was this section helpful?