Customer Module

In this section of the documentation, you will find resources to learn more about the Customer Module and how to use it in your application.

Looking for no-code docs?Refer to the Medusa Admin User Guide to learn how to manage customers and groups using the dashboard.

Medusa has customer related features available out-of-the-box through the Customer Module. A module is a standalone package that provides features for a single domain. Each of Medusa's commerce features are placed in commerce modules, such as this Customer Module.

NoteLearn more about why modules are isolated in this documentation.

Customer Features#


How to Use the Customer Module#

In your Medusa application, you build flows around commerce modules. A flow is built as a Workflow, which is a special function composed of a series of steps that guarantees data consistency and reliable roll-back mechanism.

You can build custom workflows and steps. You can also re-use Medusa's workflows and steps, which are provided by the @medusajs/medusa/core-flows package.

For example:

src/workflows/create-customer.ts
1import { 2  createWorkflow, 3  WorkflowResponse,4  createStep,5  StepResponse,6} from "@medusajs/framework/workflows-sdk"7import { Modules } from "@medusajs/framework/utils"8
9const createCustomerStep = createStep(10  "create-customer",11  async ({}, { container }) => {12    const customerModuleService = container.resolve(Modules.CUSTOMER)13
14    const customer = await customerModuleService.createCustomers({15      first_name: "Peter",16      last_name: "Hayes",17      email: "peter.hayes@example.com",18    })19
20    return new StepResponse({ customer }, customer.id)21  },22  async (customerId, { container }) => {23    if (!customerId) {24      return25    }26    const customerModuleService = container.resolve(Modules.CUSTOMER)27
28    await customerModuleService.deleteCustomers([customerId])29  }30)31
32export const createCustomerWorkflow = createWorkflow(33  "create-customer",34  () => {35    const { customer } = createCustomerStep()36
37    return new WorkflowResponse({38      customer,39    })40  }41)

You can then execute the workflow in your custom API routes, scheduled jobs, or subscribers:

Learn more about workflows in this documentation.


Was this page helpful?
Edit this page
Ask Anything
FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break