Storefront Token
/graphql-storefrontThe GraphQL Storefront API enables querying storefront data for headless commerce, Stencil themes, and custom shopping experiences. It provides read-only access to catalog data, carts, checkout, and c
<overview> The GraphQL Storefront API enables querying storefront data for headless commerce, Stencil themes, and custom shopping experiences. It provides read-only access to catalog data, shopping carts, checkout, and customer information. For mutations and admin operations, use REST APIs. </overview> <endpoint> `` POST https://{store_domain}/graphql Authorization: Bearer {storefront_token} Content-Type: application/json ` Replace {store_domain} with your storefront URL (e.g., store.mybigcommerce.com or custom domain). </endpoint> <authentication> <token_types> **Storefront Token:** - Anonymous shopper queries - Public catalog data - Create via REST API **Customer Impersonation Token:** - Customer-specific data (wishlists, account info) - Server-to-server requests - More secure, limited exposure </token_types> <creating_tokens> `bash # Storefront Token POST /v3/storefront/api-token { "channel_id": 1, "expires_at": 1893456000, "allowed_cors_origins": ["https://your-site.com"] } # Customer Impersonation Token POST /v3/storefront/api-token-customer-impersonation { "channel_id": 1, "expires_at": 1893456000 } ` </creating_tokens> <best_practices> - Rotate tokens regularly - Use short expiration for client-side tokens - Customer impersonation tokens for server-side only - Respect Principle of Least Privilege </best_practices> </authentication> <common_queries> <get_products> `graphql query GetProducts($first: Int!) { site { products(first: $first) { edges { node { entityId name sku path prices { price { value currencyCode } salePrice { value } } defaultImage { url(width: 500) } variants { edges { node { entityId sku inventory { isInStock aggregated { availableToSell } } } } } } } pageInfo { hasNextPage endCursor } } } } ` </get_products> <get_category> `graphql query GetCategory($path: String!) { site { route(path: $path) { node { ... on Category { entityId name description products { edges { node { entityId name prices { price { value } } } } } } } } } } ` </get_category> <search_products> `graphql query SearchProducts($searchTerm: String!) { site { search { searchProducts(filters: {searchTerm: $searchTerm}) { products { edges { node { entityId name path } } } } } } } ` </search_products> <get_customer> Requires customer impersonation token or logged-in customer context: `graphql query GetCustomer { customer { entityId email firstName lastName company customerGroupId addresses { edges { node { entityId firstName lastName address1 city stateOrProvince postalCode countryCode } } } } } ` </get_customer> </common_queries> <cart_operations> <create_cart> `graphql mutation CreateCart($input: CreateCartInput!) { cart { createCart(input: $input) { cart { entityId lineItems { physicalItems { entityId productEntityId variantEntityId name quantity extendedSalePrice { value } } } } } } } ` Variables: ``json { "input": { "lineItems": [ { "productEntityId": 123, "variantEntityId": 456, "quantity": 2 } ] } }