Skip to main content
Fluid gives you everything you need to build a fully functional shopping cart — a product catalog API, a cart API for managing line items, the FairShare SDK for client-side interactions, and webhooks for real-time event handling. Follow the steps below to go from fetching your first product to completing a checkout.
This guide shows two cart APIs side by side: the direct REST calls below go to the Checkout API, while the @fluid-app FairShare SDK calls the Fluid Public SDK API. Both read and write the same cart records, but their request shapes differ. Drive any one cart through a single surface. See Choosing a cart surface.
Use the built-in <fluid-cart-widget> custom element for a zero-code cart UI. Drop it anywhere in your HTML and it renders a fully styled cart drawer with no additional configuration required.
1

Fetch Product Details

Before adding anything to a cart, retrieve the product you want to sell. The public product read is unauthenticated — no token required — and resolves a product by its URL slug on your company subdomain:
The product is returned under a product envelope. It carries the display title, pricing, stock status, media, and a variants array — each variant has the id you pass when adding items to the cart. See the Public product by slug endpoint reference for the full response schema.
2

Create a Cart

Create a new cart for the current session with POST /api/checkout/v2026-04/carts. The body requires fluid_shop (your company subdomain) and country_code (an ISO country code); you can seed the cart with an items array in the same call. Creating a cart is a public operation — it needs no Bearer token.
The created cart is returned under a cart key, including the cart_token — store this in the user’s session or local storage, since it identifies the cart for every subsequent operation. The hosted checkout link comes back as meta.checkout_url. See the Create a cart endpoint reference for the full response schema.
3

Add Items to the Cart

You have two approaches for adding items to a cart.Option A — FairShare SDK (recommended for client-side apps)Call addCartItems() with an array of items — each with a variant_id and quantity:
This method posts to the Fluid Public SDK API’s Adds items to cart operation — a different operation from the one Option C calls. See Cart API for the operation behind every SDK cart method.Option B — Declarative HTML attributeAdd a data-fluid-add-to-cart attribute to any button, setting its value to the variant ID. The SDK intercepts clicks and handles the API call automatically:
Option C — Direct API callUse POST /api/checkout/v2026-04/carts/{cart_token}/items to add line items directly. This example adds one new variant. See the endpoint reference for the current authentication model and the full set of supported batch shapes.
See the Add items to cart endpoint reference for the full request and response schema.
4

Display the Cart Count

Render a live item count anywhere on the page using the fluid-cart-count element. The SDK keeps it in sync automatically as items are added or removed:
You can style this element freely with CSS. The SDK sets its textContent to the current total item count whenever the cart changes.
5

Handle Checkout

When the customer is ready to purchase, send them to checkout using the SDK or the URL returned in the cart response.Via the FairShare SDK:
Via the cart response:The meta.checkout_url returned when you created the cart is always valid. Redirect the user directly to that URL at any point.

Real-Time Cart Updates

Subscribe to cart events using Fluid webhooks to trigger downstream actions — send abandonment emails, update inventory, or sync to your CRM in real time.

Register a Webhook

Create a subscription with POST /api/company/webhooks. A subscription pairs a resource with an event on that resource (the short event name, e.g. updated), the url Fluid delivers to, and an auth_token shared secret you use to verify deliveries:
Discover the valid resource/event pairs before you register with GET /api/company/webhooks/resources. For registering, managing, verifying, and inspecting webhooks in full, see the Register and handle webhooks guide.

Handle Incoming Events

Every delivery arrives as the envelope { id, identifier, name, timestamp, payload }, with the resource data keyed by its own name inside payload — a cart delivery carries payload.cart. Always verify the signature against your auth_token before trusting a delivery (see the webhooks guide for the exact HMAC scheme):