Skip to content

Storefront API guide

Build a storefront with the EdgeCart Storefront API and publishable key.

The Storefront API is the public surface behind the EdgeCart storefront. It is designed for browsers: the key is publishable, and customer data uses the customer’s session.

Bootstrap without a key

A browser cannot send a publishable key before it has one, so the first call is key-free:

import {
  createStorefrontApi,
  fetchStorefrontConfig,
} from "@edgecart/storefront-api";

const config = await fetchStorefrontConfig("demo");

const api = createStorefrontApi({
  publishableKey: config.publishable_key!,
  apiBaseUrl: "https://shop.example/api",
});

fetchStorefrontConfig(handle?) returns the store profile, default region, supported locales, default currency, and publishable key. See the operation reference.

Browsing and cart

const { products } = await api.products.list({ limit: 20 });
const product = await api.products.get(products[0].id);
const cart = await api.carts.create({ region_id });
const updated = await api.carts.lineItems.add(cart.id, {
  variant_id,
  quantity: 1,
});

Every keyed request sends x-publishable-api-key. The key is public by design; never use a secret key in a browser. See the generated operations for listing products, retrieving a product, listing categories, listing collections, and creating a cart.

Cart operations return the recalculated cart: retrieve, update, add a line item, update a line item, and remove a line item.

Checkout sequence

  1. Create or retrieve the cart.
  2. Add line items and update the cart’s email, addresses, and region.
  3. List shipping options and add a shipping method.
  4. Optionally apply a promotion code.
  5. Create a payment collection for the cart.
  6. Create a payment session with the stripe or manual provider.
  7. Authorize the session when the provider flow requires it, then complete the cart with an Idempotency-Key.
  8. Read the created order with the returned guest_token or the customer’s session: retrieve an order.

Completion runs merchant rules and plugin checkout hooks. A blocked rule fails the request before any order is written. The Cart, Orders, and Payments modules explain what each step does.

Customer accounts

Customer account routes require the customer’s session cookie in addition to the publishable key. Guest carts are stored in the browser’s sessionStorage and synced through the API.

Errors

Non-2xx responses become StorefrontApiError with status, type, and code. Guest reads fail customer- and group-specific pricing rules closed; a signed-in customer session is required for those rules.

Type to search…

↑↓ navigate↵ selectEsc close