* fixed typedoc plugin's escape strategy * move props comments to the associated property * regenerate references
1087 lines
32 KiB
Plaintext
1087 lines
32 KiB
Plaintext
---
|
|
displayed_sidebar: jsClientSidebar
|
|
slug: /references/js-client/AdminUsersResource
|
|
---
|
|
|
|
import ParameterTypes from "@site/src/components/ParameterTypes"
|
|
|
|
# AdminUsersResource
|
|
|
|
This class is used to send requests to [Admin User API Routes](https://docs.medusajs.com/api/admin#users). All its method
|
|
are available in the JS Client under the `medusa.admin.users` property.
|
|
|
|
All methods in this class require [user authentication](AdminAuthResource.mdx#createsession).
|
|
|
|
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](https://docs.medusajs.com/modules/users/admin/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
|
|
|
|
```ts
|
|
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
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "payload",
|
|
"type": "[AdminCreateUserPayload](../internal/types/internal.AdminCreateUserPayload.mdx)",
|
|
"description": "The user to create.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "customHeaders",
|
|
"type": "`Record<string, any>`",
|
|
"description": "Custom headers to attach to the request.",
|
|
"optional": false,
|
|
"defaultValue": "{}",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "ResponsePromise",
|
|
"type": "[ResponsePromise](../internal/types/internal.ResponsePromise.mdx)<[AdminUserRes](../internal/types/internal.AdminUserRes.mdx)>",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"description": "Resolves to the user's details.",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "AdminUserRes",
|
|
"type": "`object`",
|
|
"description": "The user's details.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "user",
|
|
"type": "[Omit](../internal/types/internal.Omit.mdx)<[User](../internal/classes/internal.User.mdx), \"password_hash\">",
|
|
"description": "User details.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "api_token",
|
|
"type": "`string`",
|
|
"description": "An API token associated with the user.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "created_at",
|
|
"type": "`Date`",
|
|
"description": "The date with timezone at which the resource was created.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "deleted_at",
|
|
"type": "`null` \\| `Date`",
|
|
"description": "The date with timezone at which the resource was deleted.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "email",
|
|
"type": "`string`",
|
|
"description": "The email of the User",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "first_name",
|
|
"type": "`string`",
|
|
"description": "The first name of the User",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "id",
|
|
"type": "`string`",
|
|
"description": "The user's ID",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "last_name",
|
|
"type": "`string`",
|
|
"description": "The last name of the User",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "metadata",
|
|
"type": "`Record<string, unknown>`",
|
|
"description": "An optional key-value map with additional details",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "role",
|
|
"type": "[UserRoles](../internal/enums/internal.internal.UserRoles.mdx)",
|
|
"description": "The user's role. These roles don't provide any different privileges.",
|
|
"optional": false,
|
|
"defaultValue": "member",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "updated_at",
|
|
"type": "`Date`",
|
|
"description": "The date with timezone at which the resource was updated.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### delete
|
|
|
|
Delete a user. Once deleted, the user will not be able to authenticate or perform admin functionalities.
|
|
|
|
#### Example
|
|
|
|
```ts
|
|
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
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "id",
|
|
"type": "`string`",
|
|
"description": "The user's ID.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "customHeaders",
|
|
"type": "`Record<string, any>`",
|
|
"description": "Custom headers to attach to the request.",
|
|
"optional": false,
|
|
"defaultValue": "{}",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "ResponsePromise",
|
|
"type": "[ResponsePromise](../internal/types/internal.ResponsePromise.mdx)<[DeleteResponse](../internal/interfaces/internal.DeleteResponse.mdx)>",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"description": "Resolves to the deletion operation's details.",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "deleted",
|
|
"type": "`boolean`",
|
|
"description": "Whether the item was deleted successfully.",
|
|
"optional": false,
|
|
"defaultValue": "true",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "id",
|
|
"type": "`string`",
|
|
"description": "The ID of the deleted item.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "object",
|
|
"type": "`string`",
|
|
"description": "The type of the deleted item.",
|
|
"optional": false,
|
|
"defaultValue": "product-collection",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### list
|
|
|
|
Retrieve all admin users.
|
|
|
|
#### Example
|
|
|
|
```ts
|
|
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)
|
|
})
|
|
```
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "customHeaders",
|
|
"type": "`Record<string, any>`",
|
|
"description": "Custom headers to attach to the request.",
|
|
"optional": false,
|
|
"defaultValue": "{}",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "ResponsePromise",
|
|
"type": "[ResponsePromise](../internal/types/internal.ResponsePromise.mdx)<[AdminUsersListRes](../internal/types/internal.AdminUsersListRes.mdx)>",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"description": "Resolves to the list of users.",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "AdminUsersListRes",
|
|
"type": "`object`",
|
|
"description": "The list of users.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "users",
|
|
"type": "[Omit](../internal/types/internal.Omit.mdx)<[User](../internal/classes/internal.User.mdx), \"password_hash\">[]",
|
|
"description": "An array of users details.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "api_token",
|
|
"type": "`string`",
|
|
"description": "An API token associated with the user.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "created_at",
|
|
"type": "`Date`",
|
|
"description": "The date with timezone at which the resource was created.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "deleted_at",
|
|
"type": "`null` \\| `Date`",
|
|
"description": "The date with timezone at which the resource was deleted.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "email",
|
|
"type": "`string`",
|
|
"description": "The email of the User",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "first_name",
|
|
"type": "`string`",
|
|
"description": "The first name of the User",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "id",
|
|
"type": "`string`",
|
|
"description": "The user's ID",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "last_name",
|
|
"type": "`string`",
|
|
"description": "The last name of the User",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "metadata",
|
|
"type": "`Record<string, unknown>`",
|
|
"description": "An optional key-value map with additional details",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "role",
|
|
"type": "[UserRoles](../internal/enums/internal.internal.UserRoles.mdx)",
|
|
"description": "The user's role. These roles don't provide any different privileges.",
|
|
"optional": false,
|
|
"defaultValue": "member",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "updated_at",
|
|
"type": "`Date`",
|
|
"description": "The date with timezone at which the resource was updated.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### 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](AdminUsersResource.mdx#sendresetpasswordtoken) method,
|
|
then use that token to reset the password in this method.
|
|
|
|
#### Example
|
|
|
|
```ts
|
|
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
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "payload",
|
|
"type": "[AdminResetPasswordRequest](../internal/classes/internal.AdminResetPasswordRequest.mdx)",
|
|
"description": "The reset details.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "email",
|
|
"type": "`string`",
|
|
"description": "The User's email.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "password",
|
|
"type": "`string`",
|
|
"description": "The User's new password.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "token",
|
|
"type": "`string`",
|
|
"description": "The password-reset token generated when the password reset was requested.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"name": "customHeaders",
|
|
"type": "`Record<string, any>`",
|
|
"description": "Custom headers to attach to the request.",
|
|
"optional": false,
|
|
"defaultValue": "{}",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "ResponsePromise",
|
|
"type": "[ResponsePromise](../internal/types/internal.ResponsePromise.mdx)<[AdminUserRes](../internal/types/internal.AdminUserRes.mdx)>",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"description": "Resolves to the user's details.",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "AdminUserRes",
|
|
"type": "`object`",
|
|
"description": "The user's details.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "user",
|
|
"type": "[Omit](../internal/types/internal.Omit.mdx)<[User](../internal/classes/internal.User.mdx), \"password_hash\">",
|
|
"description": "User details.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "api_token",
|
|
"type": "`string`",
|
|
"description": "An API token associated with the user.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "created_at",
|
|
"type": "`Date`",
|
|
"description": "The date with timezone at which the resource was created.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "deleted_at",
|
|
"type": "`null` \\| `Date`",
|
|
"description": "The date with timezone at which the resource was deleted.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "email",
|
|
"type": "`string`",
|
|
"description": "The email of the User",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "first_name",
|
|
"type": "`string`",
|
|
"description": "The first name of the User",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "id",
|
|
"type": "`string`",
|
|
"description": "The user's ID",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "last_name",
|
|
"type": "`string`",
|
|
"description": "The last name of the User",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "metadata",
|
|
"type": "`Record<string, unknown>`",
|
|
"description": "An optional key-value map with additional details",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "role",
|
|
"type": "[UserRoles](../internal/enums/internal.internal.UserRoles.mdx)",
|
|
"description": "The user's role. These roles don't provide any different privileges.",
|
|
"optional": false,
|
|
"defaultValue": "member",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "updated_at",
|
|
"type": "`Date`",
|
|
"description": "The date with timezone at which the resource was updated.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### retrieve
|
|
|
|
Retrieve an admin user's details.
|
|
|
|
#### Example
|
|
|
|
```ts
|
|
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
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "id",
|
|
"type": "`string`",
|
|
"description": "The user's ID.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "customHeaders",
|
|
"type": "`Record<string, any>`",
|
|
"description": "Custom headers to attach to the request.",
|
|
"optional": false,
|
|
"defaultValue": "{}",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "ResponsePromise",
|
|
"type": "[ResponsePromise](../internal/types/internal.ResponsePromise.mdx)<[AdminUserRes](../internal/types/internal.AdminUserRes.mdx)>",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"description": "Resolves to the user's details.",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "AdminUserRes",
|
|
"type": "`object`",
|
|
"description": "The user's details.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "user",
|
|
"type": "[Omit](../internal/types/internal.Omit.mdx)<[User](../internal/classes/internal.User.mdx), \"password_hash\">",
|
|
"description": "User details.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "api_token",
|
|
"type": "`string`",
|
|
"description": "An API token associated with the user.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "created_at",
|
|
"type": "`Date`",
|
|
"description": "The date with timezone at which the resource was created.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "deleted_at",
|
|
"type": "`null` \\| `Date`",
|
|
"description": "The date with timezone at which the resource was deleted.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "email",
|
|
"type": "`string`",
|
|
"description": "The email of the User",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "first_name",
|
|
"type": "`string`",
|
|
"description": "The first name of the User",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "id",
|
|
"type": "`string`",
|
|
"description": "The user's ID",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "last_name",
|
|
"type": "`string`",
|
|
"description": "The last name of the User",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "metadata",
|
|
"type": "`Record<string, unknown>`",
|
|
"description": "An optional key-value map with additional details",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "role",
|
|
"type": "[UserRoles](../internal/enums/internal.internal.UserRoles.mdx)",
|
|
"description": "The user's role. These roles don't provide any different privileges.",
|
|
"optional": false,
|
|
"defaultValue": "member",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "updated_at",
|
|
"type": "`Date`",
|
|
"description": "The date with timezone at which the resource was updated.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### 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](AdminUsersResource.mdx#resetpassword) method.
|
|
|
|
#### Example
|
|
|
|
```ts
|
|
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
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "payload",
|
|
"type": "[AdminResetPasswordTokenRequest](../internal/classes/internal.AdminResetPasswordTokenRequest.mdx)",
|
|
"description": "The user's reset details.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "email",
|
|
"type": "`string`",
|
|
"description": "The User's email.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"name": "customHeaders",
|
|
"type": "`Record<string, any>`",
|
|
"description": "Custom headers to attach to the request.",
|
|
"optional": false,
|
|
"defaultValue": "{}",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "ResponsePromise",
|
|
"type": "[ResponsePromise](../internal/types/internal.ResponsePromise.mdx)<void>",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"description": "Resolves when the token is generated successfully.",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### update
|
|
|
|
Update an admin user's details.
|
|
|
|
#### Example
|
|
|
|
```ts
|
|
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
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "id",
|
|
"type": "`string`",
|
|
"description": "The user's ID.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "payload",
|
|
"type": "[AdminUpdateUserPayload](../internal/types/internal.AdminUpdateUserPayload.mdx)",
|
|
"description": "The attributes to update in the user.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "api_token",
|
|
"type": "`string`",
|
|
"description": "The API token of the User.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "first_name",
|
|
"type": "`string`",
|
|
"description": "The first name of the User.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "last_name",
|
|
"type": "`string`",
|
|
"description": "The last name of the User.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "metadata",
|
|
"type": "`Record<string, unknown>`",
|
|
"description": "An optional set of key-value pairs with additional information.",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "role",
|
|
"type": "[UpdateUserRoles](../internal/types/internal.UpdateUserRoles.mdx)",
|
|
"description": "",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"name": "customHeaders",
|
|
"type": "`Record<string, any>`",
|
|
"description": "Custom headers to attach to the request.",
|
|
"optional": false,
|
|
"defaultValue": "{}",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "ResponsePromise",
|
|
"type": "[ResponsePromise](../internal/types/internal.ResponsePromise.mdx)<[AdminUserRes](../internal/types/internal.AdminUserRes.mdx)>",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"description": "Resolves to the user's details.",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "AdminUserRes",
|
|
"type": "`object`",
|
|
"description": "The user's details.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "user",
|
|
"type": "[Omit](../internal/types/internal.Omit.mdx)<[User](../internal/classes/internal.User.mdx), \"password_hash\">",
|
|
"description": "User details.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": [
|
|
{
|
|
"name": "api_token",
|
|
"type": "`string`",
|
|
"description": "An API token associated with the user.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "created_at",
|
|
"type": "`Date`",
|
|
"description": "The date with timezone at which the resource was created.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "deleted_at",
|
|
"type": "`null` \\| `Date`",
|
|
"description": "The date with timezone at which the resource was deleted.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "email",
|
|
"type": "`string`",
|
|
"description": "The email of the User",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "first_name",
|
|
"type": "`string`",
|
|
"description": "The first name of the User",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "id",
|
|
"type": "`string`",
|
|
"description": "The user's ID",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "last_name",
|
|
"type": "`string`",
|
|
"description": "The last name of the User",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "metadata",
|
|
"type": "`Record<string, unknown>`",
|
|
"description": "An optional key-value map with additional details",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "role",
|
|
"type": "[UserRoles](../internal/enums/internal.internal.UserRoles.mdx)",
|
|
"description": "The user's role. These roles don't provide any different privileges.",
|
|
"optional": false,
|
|
"defaultValue": "member",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "updated_at",
|
|
"type": "`Date`",
|
|
"description": "The date with timezone at which the resource was updated.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]} />
|