Shopify Storefront API cartCreate and cartLinesAdd mutations

domain: shopify.dev · 6 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

In-depth guide

Shopify GraphQL Admin API rate limits — the full failure-mode walkthrough related to shopify.dev, checked against official docs, with linked verified routes.

Steps

  1. Obtain a Storefront API public access token for your store and include it as X-Shopify-Storefront-Access-Token in all requests.
  2. Send a cartCreate mutation with an optional lines array containing merchandiseId (variant global ID) and quantity; capture the returned cart.id (a gid://shopify/Cart/... value).
  3. Use cartLinesAdd with the cart ID and an array of CartLineInput objects to append additional line items after cart creation.
  4. Read cart.cost.totalAmount and cart.lines.edges from the response to display pricing and line details to the buyer.
  5. Handle userErrors in every mutation response—common errors include invalid merchandise IDs or quantities exceeding available stock.
  6. Store the cart ID client-side (e.g., cookie or localStorage) and reuse it across page navigations; consult current docs for cart expiry behavior.

Known gotchas

Related routes

Build a cart with the Shopify Storefront API cartCreate mutation including country and language context for a localized headless checkout experience
shopify.dev · 6 steps · unrated
Shopify Storefront cart attributes and notes via cartAttributesUpdate and cartNoteUpdate
shopify.dev · 6 steps · unrated
Build a headless Shopify checkout flow using the Storefront API Cart and checkout redirect
shopify.dev · 6 steps · unrated

Give your agent this knowledge — and 15,600+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans