How to work with the APIs for customers.
APIs
| Resource | Purpose | Reference |
|---|---|---|
| Customers | Represent a person purchasing Products. | Customers |
| Customer Groups | Assign special prices to specific products based on a Customer Group. | Customer Groups |
| Customer Search | Search across a large number of Customers in a Project, for back-office use cases. | Customer Search |
| Me endpoints | Access the resources of a single Customer. | Me endpoints overview |
Data model
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:
| From | To | Cardinality | Kind | Rule |
|---|---|---|---|---|
| Customer | Address | One to many | Embedded | The addresses are in the addresses array. Other fields of the Customer refer to them by id. See Customer addresses. |
| Customer | Store, through stores | Many to many | Reference by key | An empty stores array makes the Customer global. See Global versus Store-specific Customers. |
| Customer | Customer Group Assignment | One to many | Embedded | Each 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. |
| Customer | Customer Group, through customerGroup | Many to one | Reference | One Customer Group per Customer. In new Projects, use the Customer Group assignments instead. See Customer Groups. |
| Business Unit | Customer Group Assignment | One to many | Embedded | Each assignment is embedded in either a Customer or a Business Unit. For the maximum number per Business Unit, see Limits. |
| Business Unit | Customer, through associates | Many to many | Embedded Associate that holds a reference | Each Associate references one Customer. |
| Cart, Order | Customer, through customerId | Many to one | ID | The field holds the id of the Customer, not a Reference. |
| Review, Shopping List, Payment, Payment Method, Quote, Staged Quote, Quote Request, Recurring Order | Customer, through customer | Many to one | Reference | Optional, except on a Quote Request. |
Keys and identifiers
- Customer: has an
idand an optional user-definedkey. Itsemailis the mandatory unique identifier, as described in Customer uniqueness. Two more user-defined identifiers are optional:customerNumber, which can't be changed once set, andexternalId. For what each identifier is for, see Customer. - Address: has an
idthat the platform generates and an optional user-definedkey. Thekeyis unique among the addresses of the Customer. - Customer Group: has an
idand an optional user-definedkey.
Authentication mode
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
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
Global versus Store-specific Customers
stores field is empty.stores field contains one or more Stores.Two different authorization flows are used depending on the type of Customer:
Customer addresses
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.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.Customer authentication (sign-in)
- 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.
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.
Cart merge during sign-in and sign-up
Cart merge is applied by default on the following endpoints:
- Create (sign up) Customer
- Create (sign up) Customer in Store
- Authenticate (sign-in) Customer
- Authenticate (sign in) Customer in Store.
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
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:
- Send an email token embedded in a link to the Customer.
- When the Customer clicks the link, optionally retrieve the Customer by the email token.
- For global Customers, use the Get Customer by email token endpoint.
- For Store-specific Customers, use the Get Customer in Store by email token endpoint.
- Verify the Customer's email. This sets the Customer's
isEmailVerifiedfield totrue.
invalidateOlderTokens on the CustomerCreateEmailToken request.isEmailVerified property is set to false.Customer password reset
To reset a Customer's password, do the following:
- Send a password reset token embedded in a link to the Customer.
- When the Customer clicks the link, optionally retrieve the Customer by the password token.
- For global Customers, use the Get Customer by password token endpoint.
- For Store-specific Customers, use the Get Customer in Store by password token endpoint.
- When the Customer enters the new password, reset the Customer's password.
invalidateOlderTokens on the CustomerCreatePasswordResetToken request.Customer permissions
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
Customer Groups
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.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.customerGroupAssignments field, up to the limit in Limits.Customer Search
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
storesRefand the expanded Stores instores. - For the Customer Group of a Customer and of each
CustomerGroupAssignment, GraphQL returns the reference incustomerGroupRefand the expanded Customer Group incustomerGroup. - The
customerSignInmutation takes aCustomerSignInDraft, the equivalent of the REST CustomerSignin. ThecustomerSignUpmutation takes aCustomerSignUpDraft, the equivalent of the REST CustomerDraft. - Both GraphQL drafts have an
anonymousCartIdfield, which the GraphQL schema marks as to be deprecated in favor ofanonymousCart. - GraphQL has no Customer Search query. To change the Customer Search status in GraphQL, use the
changeCustomerSearchStatusProject update action.
Eventual consistency
Messages and events
Limits
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.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.500 Customer Groups.10 000 addresses per Customer can be indexed for Customer Search.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.