Skip to main content
When the Stockful app embed is enabled, a lightweight JavaScript API is exposed at window.stockful. It provides methods to fetch live inventory data, with built-in caching. The JS bundle is under 2 KB and loads with defer - it won’t block page rendering.

Setup

The API is automatically available when the Stockful app embed is enabled in the theme editor (App embeds > Stockful). No additional setup is required.

Waiting for the API

The API dispatches a stockful:ready event on window once initialized:

Methods

getVariant

Fetch inventory data for a single product variant.
Parameters:
  • variantId - Shopify numeric variant ID
Returns: VariantData object or null if not found.

getProduct

Fetch aggregated inventory data for a product (across all variants).
Parameters:
  • productId - Shopify numeric product ID
Returns: ProductData object or null if not found.

getVariants

Fetch inventory data for multiple variants in a single request.
Parameters:
  • variantIds - Array of Shopify numeric variant IDs (max 50)
Returns: Array of VariantData objects. Variants not found are omitted.

getLocationAvailability

Fetch per-location stock for a variant. This returns live data from Shopify.
Parameters:
  • variantId - Shopify numeric variant ID
Returns: Array of LocationData objects, filtered by the store’s visibility settings.

Types

VariantData

ProductData

LocationData

Events

stockful:ready

Dispatched on window when the API has initialized.

Caching

All methods cache responses in memory for 30 seconds. The server also returns Cache-Control headers (30s for variant/product data, 60s for location data), so the browser may serve cached responses beyond the JS cache. There is no manual cache invalidation - after 30 seconds, the next call for the same data will make a fresh request.