# findOrCreateCustomerStep - Medusa Core Workflows Reference

This documentation provides a reference to the `findOrCreateCustomerStep`. It belongs to the `@medusajs/medusa/core-flows` package.

This step finds or creates a customer based on the provided ID or email. It prioritizes finding the customer by ID, then by email.

The step creates a new customer either if:

- No customer is found with the provided ID and email;
- Or if it found the customer by ID but their email does not match the email in the input.

The step returns the details of the customer found or created, along with their email.

```ts title="src/workflows/my-workflow.ts"
import { createWorkflow } from "@medusajs/framework/workflows-sdk"
import { findOrCreateCustomerStep } from "@medusajs/medusa/core-flows"

const myWorkflow = createWorkflow(
  "my-workflow",
  () => {
    const data = findOrCreateCustomerStep({})
  }
)
```

## Input

- FindOrCreateCustomerStepInput: (\[FindOrCreateCustomerStepInput]\(../../../../interfaces/core\_flows.FindOrCreateCustomerStepInput/page.mdx)) The details of the customer to find or create.

  - customerId: (\`null\` \\| \`string\`) The ID of the customer to find.

  - email: (\`null\` \\| \`string\`) If the \`customerId\` isn't specified,
    find a customer with this email or create a new customer having this email.

## Output

- FindOrCreateCustomerOutputStepOutput: (\[FindOrCreateCustomerOutputStepOutput]\(../../../../interfaces/core\_flows.FindOrCreateCustomerOutputStepOutput/page.mdx)) The details of the customer found or created.

  - customer: (\`null\` \\| \[CustomerDTO]\(../../../../../customer/interfaces/customer.CustomerDTO/page.mdx)) The customer found or created, if any.

    - id: (\`string\`) The ID of the customer.

    - email: (\`string\`) The email of the customer.

    - has\_account: (\`boolean\`) A flag indicating if customer has an account or not.

    - default\_billing\_address\_id: (\`null\` \\| \`string\`) The associated default billing address's ID.

    - default\_shipping\_address\_id: (\`null\` \\| \`string\`) The associated default shipping address's ID.

    - company\_name: (\`null\` \\| \`string\`) The company name of the customer.

    - first\_name: (\`null\` \\| \`string\`) The first name of the customer.

    - last\_name: (\`null\` \\| \`string\`) The last name of the customer.

    - addresses: (\[CustomerAddressDTO]\(../../../../../customer/interfaces/customer.CustomerAddressDTO/page.mdx)\[]) The addresses of the customer.

      - id: (\`string\`) The ID of the customer address.

      - is\_default\_shipping: (\`boolean\`) Whether the customer address is default shipping.

      - is\_default\_billing: (\`boolean\`) Whether the customer address is default billing.

      - customer\_id: (\`string\`) The associated customer's ID.

      - created\_at: (\`string\`) The created at of the customer address.

      - updated\_at: (\`string\`) The updated at of the customer address.

      - address\_name: (\`string\`) The address name of the customer address.

      - company: (\`string\`) The company of the customer address.

      - first\_name: (\`string\`) The first name of the customer address.

      - last\_name: (\`string\`) The last name of the customer address.

      - address\_1: (\`string\`) The address 1 of the customer address.

      - address\_2: (\`string\`) The address 2 of the customer address.

      - city: (\`string\`) The city of the customer address.

      - country\_code: (\`string\`) The country code of the customer address.

      - province: (\`string\`) The lower-case \[ISO 3166-2]\(https://en.wikipedia.org/wiki/ISO\\\_3166-2) province of the customer address.

      - postal\_code: (\`string\`) The postal code of the customer address.

      - phone: (\`string\`) The phone of the customer address.

      - metadata: (\`Record\<string, unknown>\`) Holds custom data in key-value pairs.

    - phone: (\`null\` \\| \`string\`) The phone of the customer.

    - groups: (\`object\`\[]) The groups of the customer.

      - id: (\`string\`) The ID of the group.

      - name: (\`string\`) The name of the group.

    - metadata: (\`Record\<string, unknown>\`) Holds custom data in key-value pairs.

    - created\_by: (\`null\` \\| \`string\`) Who created the customer.

    - deleted\_at: (\`null\` \\| \`string\` \\| \`Date\`) The deletion date of the customer.

    - created\_at: (\`string\` \\| \`Date\`) The creation date of the customer.

    - updated\_at: (\`string\` \\| \`Date\`) The update date of the customer.

  - email: (\`null\` \\| \`string\`) The email of the customer found or created, if any.


---

The best way to deploy Medusa is through Medusa Cloud where you get autoscaling production infrastructure fine tuned for Medusa. Create an account by signing up at cloud.medusajs.com/signup.
