--- displayed_sidebar: jsClientSidebar slug: /references/js-client/AdminCustomersResource --- import ParameterTypes from "@site/src/components/ParameterTypes" # AdminCustomersResource This class is used to send requests to [Admin Customer API Routes](https://docs.medusajs.com/api/admin#customers). All its method are available in the JS Client under the `medusa.admin.customers` property. All methods in this class require [user authentication](AdminAuthResource.mdx#createsession). Customers can either be created when they register through the [CustomersResource.create](CustomersResource.mdx#create) method, or created by the admin using the [create](AdminCustomersResource.mdx#create) method. Related Guide: [How to manage customers](https://docs.medusajs.com/modules/customers/admin/manage-customers). ## Methods ### create Create a customer as an admin. #### 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.customers .create({ email: "user@example.com", first_name: "Caterina", last_name: "Yost", password: "supersecret", }) .then(({ customer }) => { console.log(customer.id) }) ``` #### Parameters `", "description": "An optional set of key-value pairs to hold additional information.", "optional": true, "defaultValue": "", "expandable": false, "children": [] }, { "name": "password", "type": "`string`", "description": "The customer's password.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "phone", "type": "`string`", "description": "The customer's phone number.", "optional": true, "defaultValue": "", "expandable": false, "children": [] } ] }, { "name": "customHeaders", "type": "`Record`", "description": "Custom headers to attach to the request.", "optional": false, "defaultValue": "{}", "expandable": false, "children": [] } ]} /> #### Returns `", "description": "An optional key-value map with additional details", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "orders", "type": "[Order](../internal/classes/internal.Order.mdx)[]", "description": "The details of the orders this customer placed.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "phone", "type": "`string`", "description": "The customer's phone number", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "shipping_addresses", "type": "[Address](../internal/classes/internal.Address.mdx)[]", "description": "The details of the shipping addresses associated with the customer.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "updated_at", "type": "`Date`", "description": "The date with timezone at which the resource was updated.", "optional": false, "defaultValue": "", "expandable": false, "children": [] } ] } ] } ] } ]} /> ___ ### list Retrieve a list of Customers. The customers can be filtered by fields such as `q` or `groups`. The customers can also be paginated. #### Example To list customers: ```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.customers.list().then(({ customers, limit, offset, count }) => { console.log(customers.length) }) ``` To specify relations that should be retrieved within the customers: ```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.customers .list({ expand: "billing_address", }) .then(({ customers, limit, offset, count }) => { console.log(customers.length) }) ``` By default, only the first `50` records are retrieved. You can control pagination by specifying the `limit` and `offset` properties: ```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.customers .list({ expand: "billing_address", limit, offset, }) .then(({ customers, limit, offset, count }) => { console.log(customers.length) }) ``` #### Parameters `", "description": "Custom headers to attach to the request.", "optional": false, "defaultValue": "{}", "expandable": false, "children": [] } ]} /> #### Returns `", "description": "An optional key-value map with additional details", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "orders", "type": "[Order](../internal/classes/internal.Order.mdx)[]", "description": "The details of the orders this customer placed.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "phone", "type": "`string`", "description": "The customer's phone number", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "shipping_addresses", "type": "[Address](../internal/classes/internal.Address.mdx)[]", "description": "The details of the shipping addresses associated with the customer.", "optional": false, "defaultValue": "", "expandable": true, "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 the details of a customer. #### 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.customers.retrieve(customerId).then(({ customer }) => { console.log(customer.id) }) ``` #### Parameters `", "description": "Custom headers to attach to the request.", "optional": false, "defaultValue": "{}", "expandable": false, "children": [] } ]} /> #### Returns `", "description": "An optional key-value map with additional details", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "orders", "type": "[Order](../internal/classes/internal.Order.mdx)[]", "description": "The details of the orders this customer placed.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "phone", "type": "`string`", "description": "The customer's phone number", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "shipping_addresses", "type": "[Address](../internal/classes/internal.Address.mdx)[]", "description": "The details of the shipping addresses associated with the customer.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "updated_at", "type": "`Date`", "description": "The date with timezone at which the resource was updated.", "optional": false, "defaultValue": "", "expandable": false, "children": [] } ] } ] } ] } ]} /> ___ ### update Update a customer'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.customers .update(customerId, { first_name: "Dolly", }) .then(({ customer }) => { console.log(customer.id) }) ``` #### Parameters `", "description": "An optional set of key-value pairs to hold additional information.", "optional": true, "defaultValue": "", "expandable": false, "children": [] }, { "name": "password", "type": "`string`", "description": "The Customer's password.", "optional": true, "defaultValue": "", "expandable": false, "children": [] }, { "name": "phone", "type": "`string`", "description": "The Customer's phone number.", "optional": true, "defaultValue": "", "expandable": false, "children": [] } ] }, { "name": "customHeaders", "type": "`Record`", "description": "Custom headers to attach to the request.", "optional": false, "defaultValue": "{}", "expandable": false, "children": [] } ]} /> #### Returns `", "description": "An optional key-value map with additional details", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "orders", "type": "[Order](../internal/classes/internal.Order.mdx)[]", "description": "The details of the orders this customer placed.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "phone", "type": "`string`", "description": "The customer's phone number", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "shipping_addresses", "type": "[Address](../internal/classes/internal.Address.mdx)[]", "description": "The details of the shipping addresses associated with the customer.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "updated_at", "type": "`Date`", "description": "The date with timezone at which the resource was updated.", "optional": false, "defaultValue": "", "expandable": false, "children": [] } ] } ] } ] } ]} />