Skip to main content
Use @stateset/embedded 1.35.1 to create a customer and reuse its returned ID throughout a local workflow. This example runs in a fresh in-memory database and needs no API key, payment provider, or subscription setup.

Prerequisites

Use Node.js 20.20.0+ and npm 10+. In a new directory:
See SDK installation if the native module cannot load.

Run the complete example

Save this as customers-demo.mjs:
Success: all assertions pass and you see:

Choose create, lookup, or update

findOrCreate is useful when the exact email is already known. It is not a profile merge or a substitute for update. This walkthrough verifies repeated calls using the same email; it does not establish alias matching, normalization rules, or concurrent import behavior. Save the returned customer ID as the relationship key for orders. If you integrate an external CRM or payment provider, maintain its customer ID separately and reconcile it explicitly. The local record does not create a provider customer or start recurring billing.

Addresses and preferences

The customer input uses firstName, lastName, and acceptsMarketing. Addresses are created with a separate method using line1, postalCode, and country; do not pass a nested REST-style customer object to this binding. The example preserves acceptsMarketing: false during a contact update. Set marketing preferences from your application’s recorded choice, rather than changing them as a side effect of an import or checkout. Adding a default customer shipping address stores that address on the customer. The order above only verifies its customerId; it does not establish that an address was copied onto the order, that postage was bought, or that any goods shipped.

Troubleshooting

Next steps

Last modified on September 20, 2026