Skip to main content

Storefront API

Requires the api_access capability enabled in shopify.extension.toml.

The Storefront API provides access to Shopify's Storefront API from within a checkout extension. Use this API to fetch product details, load collection data, and query any resource available through Shopify's Storefront API.

  • Fetch product recommendations: Query the Storefront API to load related products and display cross-sell or upsell offers in checkout.
  • Load collection metadata: Retrieve collection details to show contextual information about items in the buyer's cart.
  • Access inventory or variant data: Query product variants and inventory levels to display availability or delivery estimates.
Support
Targets (33)

The shopify global object provides access to the Storefront GraphQL API. Use shopify.query() or the shopify:storefront fetch protocol to execute GraphQL queries. Available to purchase extension targets.

Anchor to query
query
<Data = unknown, Variables = Record<string, unknown>>(query: string, options?: { variables?: Variables; version?: ; }) => Promise<{ data?: Data; errors?: []; }>
required

The method used to query the Storefront GraphQL API with a prefetched token.


  • Prefer shopify.query() over raw fetch(): The query() helper handles authentication, versioning, and error formatting automatically. Use fetch() with the shopify:storefront protocol only when you need lower-level control over the request.
  • Minimize query complexity: Checkout extensions run in a latency-sensitive context. Request only the fields you need and avoid deeply nested queries to keep the checkout fast.
  • Handle loading and error states: Storefront API requests are asynchronous. The query() method returns both data and errors, and a response might contain partial data alongside errors. Show a loading indicator while data loads and display a graceful fallback if the request fails or returns errors.

  • The Storefront API requires the api_access capability in shopify.extension.toml. Without it, shopify.query() isn't available and fetch() calls to shopify:storefront are rejected.
  • Storefront API rate limits apply to all queries made from checkout extensions. Heavy or frequent queries may be throttled, which can slow down the checkout experience.

Was this page helpful?