|
| 1 | +--- |
| 2 | +title: Storefront GraphQL API |
| 3 | +--- |
| 4 | + |
| 5 | +import { Callout } from 'fumadocs-ui/components/callout'; |
| 6 | + |
| 7 | +Build custom sidecarts, upsell flows, and dynamic storefront experiences with the Storefront GraphQL API. Query products, manage carts, apply vouchers, and handle user accounts — all from your theme's JavaScript or any client-side application. |
| 8 | + |
| 9 | +## API Endpoint |
| 10 | + |
| 11 | +Every store exposes a GraphQL endpoint at: |
| 12 | + |
| 13 | +``` |
| 14 | +POST https://{store}.29next.store/api/graphql/ |
| 15 | +``` |
| 16 | + |
| 17 | +All requests must be `POST` with `Content-Type: application/json`. Replace `{store}` with your store's subdomain. |
| 18 | + |
| 19 | +## Authentication |
| 20 | + |
| 21 | +The Storefront API is available within the context of your storefront on a storefront domain. Requests made from your theme's JavaScript automatically inherit the user's session — no API keys or tokens needed. |
| 22 | + |
| 23 | +<Callout type="info"> |
| 24 | +External access to the Storefront API (outside of the storefront context) will be available in future iterations. |
| 25 | +</Callout> |
| 26 | + |
| 27 | + |
| 28 | +## Interactive Explorer (GraphiQL) |
| 29 | + |
| 30 | +Every store includes a built-in **GraphiQL IDE** — an in-browser tool for writing, validating, and testing GraphQL queries directly against your store's schema. Navigate to `/api/graphql/` on your store to open it. |
| 31 | + |
| 32 | +GraphiQL lets you: |
| 33 | + |
| 34 | +- **Explore the schema** — browse all available queries, mutations, types, and their fields using the documentation sidebar |
| 35 | +- **Build queries visually** — use the explorer panel to construct queries by selecting fields, without writing GraphQL by hand |
| 36 | +- **Test in real-time** — run queries and mutations against your store and see the JSON response instantly |
| 37 | +- **Validate syntax** — get inline error highlighting and autocomplete as you type |
| 38 | + |
| 39 | +``` |
| 40 | +https://{store}.29next.store/api/graphql/ |
| 41 | +``` |
| 42 | + |
| 43 | +This is the fastest way to learn what the API offers and prototype queries before adding them to your theme code. |
| 44 | + |
| 45 | + |
| 46 | +## API Reference |
| 47 | + |
| 48 | +### Queries |
| 49 | + |
| 50 | +- [`cart`](/docs/storefront/graphql/queries/cart) — Retrieve a cart by ID |
| 51 | +- [`me`](/docs/storefront/graphql/queries/me) — Get the current authenticated user |
| 52 | +- [`product`](/docs/storefront/graphql/queries/product) — Fetch a single product |
| 53 | +- [`products`](/docs/storefront/graphql/queries/products) — Query the product catalog |
| 54 | + |
| 55 | +### Mutations |
| 56 | + |
| 57 | +- [`createCart`](/docs/storefront/graphql/mutations/create-cart) — Create a new cart |
| 58 | +- [`addCartLines`](/docs/storefront/graphql/mutations/add-cart-lines) — Add line items to a cart |
| 59 | +- [`updateCartLines`](/docs/storefront/graphql/mutations/update-cart-lines) — Update quantities on existing cart lines |
| 60 | +- [`removeCartLines`](/docs/storefront/graphql/mutations/remove-cart-lines) — Remove line items from a cart |
| 61 | +- [`emptyCart`](/docs/storefront/graphql/mutations/empty-cart) — Remove all items from a cart |
| 62 | +- [`addVoucher`](/docs/storefront/graphql/mutations/add-voucher) — Apply a voucher code to a cart |
| 63 | +- [`removeVoucher`](/docs/storefront/graphql/mutations/remove-voucher) — Remove a voucher from a cart |
| 64 | +- [`updateCartAttribution`](/docs/storefront/graphql/mutations/update-cart-attribution) — Set UTM and affiliate attribution on a cart |
| 65 | +- [`updateCartMetadata`](/docs/storefront/graphql/mutations/update-cart-metadata) — Update custom metadata on a cart |
| 66 | +- [`register`](/docs/storefront/graphql/mutations/register) — Register a new customer account |
| 67 | +- [`tokenAuth`](/docs/storefront/graphql/mutations/token-auth) — Authenticate and obtain a token |
| 68 | +- [`verifyToken`](/docs/storefront/graphql/mutations/verify-token) — Verify an authentication token |
| 69 | +- [`updateAccount`](/docs/storefront/graphql/mutations/update-account) — Update the current user's account details |
| 70 | + |
| 71 | + |
| 72 | +## Quick start |
| 73 | + |
| 74 | +Fetch the current cart to build a custom sidecart UI: |
| 75 | + |
| 76 | +```bash title="Example: Query the cart" |
| 77 | +curl -X POST https://yourstore.29next.store/api/graphql/ \ |
| 78 | + -H "Content-Type: application/json" \ |
| 79 | + -d '{ |
| 80 | + "query": "query Cart($id: ID!) { cart(id: $id) { id numItems totalInclTax currency lines { edges { node { id quantity product { title } linePriceInclTax } } } } }", |
| 81 | + "variables": { "id": "<cart-id>" } |
| 82 | + }' |
| 83 | +``` |
| 84 | + |
| 85 | +```json title="Response" |
| 86 | +{ |
| 87 | + "data": { |
| 88 | + "cart": { |
| 89 | + "id": "Q2FydE5vZGU6MTIz", |
| 90 | + "numItems": 2, |
| 91 | + "totalInclTax": "59.98", |
| 92 | + "currency": "USD", |
| 93 | + "lines": { |
| 94 | + "edges": [ |
| 95 | + { |
| 96 | + "node": { |
| 97 | + "id": "Q2FydExpbmVOb2RlOjE=", |
| 98 | + "quantity": 1, |
| 99 | + "product": { "title": "Premium Supplement" }, |
| 100 | + "linePriceInclTax": "29.99" |
| 101 | + } |
| 102 | + } |
| 103 | + ] |
| 104 | + } |
| 105 | + } |
| 106 | + } |
| 107 | +} |
| 108 | +``` |
| 109 | + |
| 110 | +## Common use cases |
| 111 | + |
| 112 | +### Custom sidecarts |
| 113 | + |
| 114 | +The most common use of the Storefront API is building custom sidecart experiences. Use `cart` queries to fetch the current cart state and render a fully custom cart drawer with your own markup, animations, and styling. |
| 115 | + |
| 116 | +### Upsells and cross-sells |
| 117 | + |
| 118 | +Add upsell products to the cart dynamically using mutations like `addCartLines`. Query the product catalog with `products` to find related items, then present them in your sidecart or on product pages. |
| 119 | + |
| 120 | +```graphql title="Add an upsell to the cart" |
| 121 | +mutation AddUpsell($input: AddCartLinesInput!) { |
| 122 | + addCartLines(input: $input) { |
| 123 | + success |
| 124 | + cart { |
| 125 | + numItems |
| 126 | + totalInclTax |
| 127 | + } |
| 128 | + } |
| 129 | +} |
| 130 | +``` |
| 131 | + |
| 132 | +### User accounts |
| 133 | + |
| 134 | +Handle customer registration and authentication directly from your storefront with `register`, `tokenAuth`, and `updateAccount` mutations. |
| 135 | + |
| 136 | +### Vouchers and discounts |
| 137 | + |
| 138 | +Apply and remove voucher codes from carts using `addVoucher` and `removeVoucher` mutations, enabling custom promo code UIs. |
| 139 | + |
| 140 | + |
| 141 | + |
0 commit comments