Customers APIs overview

Ask about this Page
Copy for AI
View as Markdown

How to work with the APIs for customers.

This page describes rules that apply across the Customers APIs. For what Customers, Customer Groups, and Customer Search are and how they behave, see the Customers overview.
Use the commercetools CLI to work with this API from your terminal or AI coding agent.

APIs

ResourcePurposeReference
CustomersRepresent a person purchasing Products.Customers
Customer GroupsAssign special prices to specific products based on a Customer Group.Customer Groups
Customer SearchSearch across a large number of Customers in a Project, for back-office use cases.Customer Search
Me endpointsAccess the resources of a single Customer.Me endpoints overview

Data model

This section describes the entities of the Customers APIs and how they relate. It covers the relationships and identifiers of each entity, using names that REST and GraphQL share. For the complete field list of an entity, follow the link to its type. For naming differences between the two APIs, see Differences between REST and GraphQL.

Entity relationships

The following diagram shows the main relationships between the entities. The table that follows lists all relationships. A Customer embeds its addresses and Customer Group assignments, and references its Stores and Customer Groups. Business Units, Carts, and Orders refer to Customers.

The following table lists each relationship, including references that other resources hold to a Customer:

FromToCardinalityKindRule
CustomerAddressOne to manyEmbeddedThe addresses are in the addresses array. Other fields of the Customer refer to them by id. See Customer addresses.
CustomerStore, through storesMany to manyReference by keyAn empty stores array makes the Customer global. See Global versus Store-specific Customers.
CustomerCustomer Group AssignmentOne to manyEmbeddedEach CustomerGroupAssignment references one Customer Group. Each assignment is embedded in either a Customer or a Business Unit. For the maximum number per Customer, see Limits.
CustomerCustomer Group, through customerGroupMany to oneReferenceOne Customer Group per Customer. In new Projects, use the Customer Group assignments instead. See Customer Groups.
Business UnitCustomer Group AssignmentOne to manyEmbeddedEach assignment is embedded in either a Customer or a Business Unit. For the maximum number per Business Unit, see Limits.
Business UnitCustomer, through associatesMany to manyEmbedded Associate that holds a referenceEach Associate references one Customer.
Cart, OrderCustomer, through customerIdMany to oneIDThe field holds the id of the Customer, not a Reference.
Review, Shopping List, Payment, Payment Method, Quote, Staged Quote, Quote Request, Recurring OrderCustomer, through customerMany to oneReferenceOptional, except on a Quote Request.

Keys and identifiers

  • Customer: has an id and an optional user-defined key. Its email is the mandatory unique identifier, as described in Customer uniqueness. Two more user-defined identifiers are optional: customerNumber, which can't be changed once set, and externalId. For what each identifier is for, see Customer.
  • Address: has an id that the platform generates and an optional user-defined key. The key is unique among the addresses of the Customer.
  • Customer Group: has an id and an optional user-defined key.

Authentication mode

The authenticationMode field of a Customer indicates whether the Customer needs a password. It is Password by default. For how each value affects the password field, see AuthenticationMode.

Working with the APIs

Customer uniqueness

A Customer's email is unique in the Project, or in the Store the Customer is assigned to. For what this means for global and Store-specific Customers, see Customer uniqueness in the Customers overview.

Email case-insensitivity

To perform a case-insensitive query for emails, convert the given email address to lowercase and use the additional query field lowercaseEmail.

Global versus Store-specific Customers

For what global and Store-specific Customers are and how they differ, see Customers overview.
A Customer is considered global when the Customer stores field is empty.
A Customer is considered Store-specific, when the Customer stores field contains one or more Stores.

Two different authorization flows are used depending on the type of Customer:

Customer addresses

A Customer stores all known addresses in a single addresses array. Each address entry has an auto-generated id and, optionally, a user-defined key. The platform uses the id to reference addresses from dedicated fields (shippingAddressIds, billingAddressIds, defaultShippingAddressId, defaultBillingAddressId) to express whether an address is used for shipping, billing, or as a default.
This ID-reference model means the same address is stored only once and can play multiple roles. For example, one address can be both a shipping and a billing address, and also the default for either. For field details, see the Customer representation.
When changing or removing an existing address, or assigning it a shipping, billing, or default role, you don't need to know the internal id. The relevant update actions accept either the address id or its key to identify the address. Removing an address also clears the Customer references to that address.
The same address-role model is used for the BusinessUnit representation.

Customer authentication (sign-in)

Customer authentication endpoints differentiate between global and store-specific Customers.
  • To authenticate a global Customer (not associated with a Store), use the general or Store-specific endpoint.
  • To authenticate a Store-specific Customer, use the Store-specific endpoint.
During the sign-in process, Customers may be assigned resources created prior to the sign-in. With anonymousCart, a single anonymous Cart can be assigned. With anonymousId, all Carts, Orders, ShoppingLists, and Payments with the same anonymousId can be assigned to the Customer. If both anonymousCart and anonymousId are defined, the anonymous Cart must have the same anonymousId assigned.

Cart assignment can happen in one of two ways:

  • If the Customer does not have an active Cart yet, or the value of AnonymousCartSignInMode is set to UseAsNewActiveCustomerCart, then the anonymous Cart becomes the Customer's Cart.
  • If the Customer already has one or more active Carts and the value of AnonymousCartSignInMode is set to MergeWithExistingCustomerCart, then the items of the anonymous Cart will be merged into the Customer's most recently modified active Cart, if the two Carts are eligible for a merge. This process is referred to as Cart merge and results in a specific set of changes for both Carts. For the eligibility conditions, see Merge a Cart.
Upon successfully signing-in a Customer, a CustomerSignInResult is returned. If the CustomerSignInResult contains a Cart, the Cart is recalculated to have up-to-date prices, taxes, discounts, and line items.

Cart merge during sign-in and sign-up

Cart merge during sign-in and sign-up is only available for Customers authenticating through the Internal OAuth. To merge Carts belonging to externally authenticated Customers, use the Merge Cart and Merge Cart in Store endpoints on the Carts API.

Cart merge is applied by default on the following endpoints:

To deactivate this feature, set the anonymousCartSignInMode field on the CustomerSignin to UseAsNewActiveCustomerCart.

The response to a sign-in or sign-up contains the Customer's most recently modified active Cart. The Customer can then modify this Cart and place an Order.

Customer email verification

Email verification follows the same set of steps for global as well as Store-specific Customers. For global Customers, use the general Customer endpoints. For Store-specific Customers, use the Customer in Store endpoints.
By default, the isEmailVerified field of a new Customer is false. For when to set it on creation, see CustomerDraft.

To verify a Customer's email, do the following:

  1. Send an email token embedded in a link to the Customer.
  2. When the Customer clicks the link, optionally retrieve the Customer by the email token.
  3. Verify the Customer's email. This sets the Customer's isEmailVerified field to true.
For an implementation of these steps with code, see Customer sign-up and email verification.
If the token is valid for 60 minutes or less, its value can be retrieved through the CustomerEmailTokenCreated Message, which enables asynchronous flows.
By default, creating an email token does not invalidate older tokens. To invalidate older tokens, set invalidateOlderTokens on the CustomerCreateEmailToken request.
The verification methods are also provided on the My Customer Profile with their respective Scopes.
When using the Change Email update action, even if the email address remains the same, the Customer's isEmailVerified property is set to false.
After the email is verified, all email tokens issued previously through this flow are invalidated. For the consistency of this invalidation, see Eventual consistency.

Customer password reset

Password reset follows the same set of steps for global as well as Store-specific Customers. For global Customers, use the general Customer endpoints. For Store-specific Customers, use the Customer in Store endpoints.

To reset a Customer's password, do the following:

  1. Send a password reset token embedded in a link to the Customer.
  2. When the Customer clicks the link, optionally retrieve the Customer by the password token.
  3. When the Customer enters the new password, reset the Customer's password.
For an implementation of these steps with code, see Password reset flow.
If the token is valid for 60 minutes or less, its value can be retrieved through the CustomerPasswordTokenCreated Message, which enables asynchronous flows.
By default, creating a password token does not invalidate older tokens. To invalidate older tokens, set invalidateOlderTokens on the CustomerCreatePasswordResetToken request.
The reset methods are also provided on the My Customer Profile with their respective Scopes.
After the password is reset, all password tokens issued previously through this flow are invalidated. In addition, any access and refresh tokens issued previously through the password flow and refresh token flow are invalidated. For the consistency of this invalidation, see Eventual consistency.

Customer permissions

An API Client with the view_customers scope provides access to all Customers in your Project. Therefore, you must implement your own data protection in your storefront or use the Me endpoints.

The following resources may contain or refer to customer data:

  • Business Unit B2B
  • Cart
  • Customer
  • Custom Object
  • Discount Code
  • Message
  • Order
  • Order Edit
  • Payment
  • Quote
  • Quote Request
  • Review
  • Shopping List
  • Staged Quote

Store-specific permissions

If you have Store-specific Customers in your Project, you can provide Store-specific access to those. Customers can be managed per Store through the Customer in Store endpoints. Carts associated with these Customers can also be retrieved per Store.
The Me endpoints are provided as Customer in Store variations with restricted access for one Store-specific Customer.

Customer Groups

The Customer customerGroup field allows assigning one Customer Group per Customer. The customerGroupAssignments field supports assigning multiple Customer Groups, up to the limit in Limits, and better supports complex pricing scenarios.
Although both fields can be used together in existing projects, use only the customerGroupAssignments field in new projects. In addition to supporting assigning multiple Customer Groups to Customers, it provides greater flexibility in complex pricing scenarios. To migrate existing Projects from using a single Customer Group per Customer to using multiple Customer Groups, see the migration guide.
You can assign Customer Groups to a Business Unit via the customerGroupAssignments field, up to the limit in Limits.
When updating the Customer Group assignments for a Customer or Business Unit, the prices in the Customer's or Associate's existing Carts are not recalculated automatically, and must be recalculated manually.
For the API rules that apply when you set up customer-specific prices for Business Units, see Business Units and Associates APIs overview.

Differences between REST and GraphQL

The entities and field names are the same in both APIs, with the following exceptions:

  • For the Stores of a Customer, GraphQL returns the Store key references in storesRef and the expanded Stores in stores.
  • For the Customer Group of a Customer and of each CustomerGroupAssignment, GraphQL returns the reference in customerGroupRef and the expanded Customer Group in customerGroup.
  • The customerSignIn mutation takes a CustomerSignInDraft, the equivalent of the REST CustomerSignin. The customerSignUp mutation takes a CustomerSignUpDraft, the equivalent of the REST CustomerDraft.
  • Both GraphQL drafts have an anonymousCartId field, which the GraphQL schema marks as to be deprecated in favor of anonymousCart.
  • GraphQL has no Customer Search query. To change the Customer Search status in GraphQL, use the changeCustomerSearchStatus Project update action.
For the GraphQL types, see the Customers and Customer Groups GraphQL references.

Eventual consistency

The invalidation of tokens after an email verification or a password reset is eventually consistent. This applies to the email tokens that were issued before an email verification, and to the password tokens, access tokens, and refresh tokens that were issued before a password reset.

Messages and events

Customers send Messages when they are created or deleted, and when their data changes, for example their addresses, email address, names, Stores, or Custom Fields. Creating an email token or a password reset token also sends a Message, and so does assigning a Customer Group to a Customer. For the full list, see Customer Messages. The Customer Search API doesn't have its own Messages.

Limits

A maximum of 10 000 000 Customers can be created per Project. A Customer can be assigned to a maximum of 500 Customer Groups. These are soft limits that can be increased per Project after a performance impact review. See Limit increase guidance.
A maximum number of 10 000 Customer Groups can be created per Project. This is a soft limit that can be increased per Project after a performance impact review. See Limit increase guidance.
A Business Unit can have up to 500 Customer Groups.
A maximum of 10 000 addresses per Customer can be indexed for Customer Search.
A maximum of 50 Custom Fields per Customer can be indexed. If a Customer has more, only the first 50 Custom Fields, sorted alphabetically by field name, are indexed.
For the full list of limits, see Customers, Customer Search, and Customer Groups on the Limits page.