Skip to content

SDK recipes

Build the common storefront pieces with the JavaScript SDK — notify-me, preorder buttons, and variant state.

BetaThe SDK is in public beta: endpoints, fields and behaviour can change before general availability. See the changelog

Last updated

Short, copy-paste recipes for the things you’ll build with the Storefront SDK. All assume an initialized client:

const stoq = await init({
shop: 'my-store.myshopify.com',
storefrontToken: '...', // public Storefront API token
})

Ask the SDK about a variant and branch on its state:

const state = await stoq.getVariantState(variantId)
if (state.isPreorder) {
// offer a preorder button
} else if (!state.availableForSale) {
// out of stock → offer notify-me
} else {
// in stock → normal add-to-cart
}
// Drop the modal in on click…
stoq.openModal(variantId)
// …or render an inline form into your own element:
stoq.openInlineForm(variantId, { target: '#notify-me' })
// Submit a signup yourself:
await stoq.createSignup({ variantId, email: 'shopper@example.com' })
// A ready-made preorder button for a variant:
const button = stoq.preorderButtonFor(variantId)
// Or build your own and add the cart line with the selling plan attached:
const line = await stoq.cartLineFor(variantId, 1)
// → pass `line` to the Storefront Cart API (cartLinesAdd)

Hooks live under the /react entry — see the headless guide for useStoqVariant, useStoqCartLine, useStoqPreorder, the <StoqPreorderButton> / <StoqNotifyMeButton> components, and toCartFormInput (builds the /cart action payload when you add from a callback).

Was this page helpful?

Still stuck? Ask Quinn or chat with support