Add a notify-me form to a custom theme section
Worked recipe: style STOQ's notify-me button and form through the settings API, then open the signup form from your own button in a custom Shopify theme section. Every call, the theme code, and how to check a signup lands.
Last updated
For: theme developers building a custom product section (a bespoke buy box, a quick view, a landing page block) where STOQ’s own Notify me button doesn’t place itself.
Goal: your own “Email me when it’s back” button in the section, shown only for sold-out variants, that opens STOQ’s signup form in the store’s brand, with signups landing on the variant’s waitlist.
Before you start
Section titled “Before you start”- Credentials: the store’s API key (
X-Auth-Token) or an MCP client signed in to the store, for the settings. The theme code needs no credentials: never put the API key in a theme. - Theme: STOQ’s app embed is on in the theme you edit (checked in step 1). This recipe uses Online Store 2.0 Liquid.
- Plan: the button and form copy, colours and placement work on every plan. The inline (on-page) form setting, the name field, marketing consent, the product image and removing “Powered by” are paid; on the free plan, writing them fails with
plan_required.
1. Check the embed and read the current widget
Section titled “1. Check the embed and read the current widget”curl "https://app.stoqapp.com/api/v2/external/account/setup" \ -H "X-Auth-Token: $STOQ_API_KEY"
curl "https://app.stoqapp.com/api/v2/external/back_in_stock/settings/widget" \ -H "X-Auth-Token: $STOQ_API_KEY"{ "tool": "execute_read", "arguments": { "method": "GET", "path": "/back_in_stock/settings/widget" } }{ "button": { "text": "Notify me when available", "text_color": "#FFFFFF", "background_color": "#000000", "border_radius": 4, "position": "auto", "font_family": "…", "…": "…" }, "placement": { "enabled": true, "show_on_collection": false, "selectors": { "product": null, "…": "…" }, "…": "…" }, "form": { "copy": { "header": "…", "button_text": "…", "…": "…" }, "messages": { "success": "…", "…": "…" }, "style": { "…": "…" }, "fields": { "…": "…" }, "inline": { "enabled": false, "selector": null, "insertion": "…" } }, "optin": { "…": "…" }, "branding": { "powered_by": true }, "custom": { "css": "…", "javascript": "…" }, "locale": "en"}If app_embed.enabled is false on /account/setup, give the merchant its theme_editor_url first. Nothing in this recipe shows on the storefront without the embed.
2. Style the button and form
Section titled “2. Style the button and form”curl -X PATCH "https://app.stoqapp.com/api/v2/external/back_in_stock/settings/widget" \ -H "X-Auth-Token: $STOQ_API_KEY" -H "Content-Type: application/json" \ -H "Idempotency-Key: $(uuidgen)" \ -d '{ "button": { "text": "Email me when it’s back", "background_color": "#1A1A1A", "text_color": "#FFFFFF", "border_radius": 8 }, "form": { "copy": { "header": "Get a restock alert", "button_text": "Notify me" }, "messages": { "success": "You’re on the list. We’ll email you when it’s back." }, "style": { "button_background_color": "#1A1A1A", "button_text_color": "#FFFFFF", "border_radius": 8 } } }'{ "tool": "execute_write", "arguments": { "method": "PATCH", "path": "/back_in_stock/settings/widget", "params": { "button": { "text": "Email me when it’s back", "background_color": "#1A1A1A", "text_color": "#FFFFFF", "border_radius": 8 }, "form": { "copy": { "header": "Get a restock alert", "button_text": "Notify me" }, "messages": { "success": "You’re on the list. We’ll email you when it’s back." }, "style": { "button_background_color": "#1A1A1A", "button_text_color": "#FFFFFF", "border_radius": 8 } } }, "idempotency_key": "<new uuid>" } }202 Accepted with the whole widget, in the same shape as step 1. The PATCH is a deep partial: send only what you change. Colours are #RRGGBB; radii are whole pixels. Add a top-level locale (such as "fr") to write the copy for one language only.
Your own button, or STOQ’s? STOQ’s button places itself after the sold-out add-to-cart button (button.position: "auto"), floats on the page edge ("float-right", "float-left"), or goes after the element a CSS selector finds ("specific", with placement.selectors.product). If your section has a stable element to anchor to, that may be all you need:
{ "tool": "execute_write", "arguments": { "method": "PATCH", "path": "/back_in_stock/settings/widget", "params": { "button": { "position": "specific" }, "placement": { "selectors": { "product": ".my-buy-box__actions" } } }, "idempotency_key": "<new uuid>" } }A wrong selector hides the button on every product page, so test it on a draft theme first. For a section STOQ can’t anchor to (a quick view, a landing page, several products on one page), use your own button, as below.
3. Get a starter snippet (optional)
Section titled “3. Get a starter snippet (optional)”Over MCP, design_theme returns a ready-to-paste theme snippet for the store:
{ "tool": "design_theme", "arguments": { "surface": "theme", "widget": "notify_me", "product_id": "8123456789" } }It returns code, not an API call. Step 4 is the same idea, written out.
4. Add the button to your section
Section titled “4. Add the button to your section”In your section’s Liquid (for example sections/my-buy-box.liquid):
{%- assign current = product.selected_or_first_available_variant -%}<div class="my-notify"> <button type="button" class="my-notify__button" {% if current.available %}hidden{% endif %}> Email me when it’s back </button> <div class="my-notify__inline"></div></div>
<script> (function () { var product = {{ product | json }}; var root = document.currentScript.previousElementSibling; var button = root.querySelector('.my-notify__button');
function selectedVariantId() { var input = document.querySelector('form[action*="/cart/add"] [name="id"]'); return input ? input.value : '{{ current.id }}'; }
function syncButton() { var id = Number(selectedVariantId()); var variant = product.variants.find(function (v) { return v.id === id; }); button.hidden = !variant || variant.available; }
button.addEventListener('click', function () { if (!window._RestockRocket || !window._RestockRocket.openModal) return; // embed not loaded yet window._RestockRocket.openModal(product, selectedVariantId()); });
document.addEventListener('change', syncButton); syncButton(); })();</script>openModal(productData, variantId, customerData)opens STOQ’s signup form for that variant, styled by step 2. Pass a logged-in customer’s{ email }ascustomerDatato prefill it.- To show the form in the section instead of a popup, call
window._RestockRocket.openInlineForm(product, selectedVariantId(), null, '.my-notify__inline', 'beforeend'), andwindow._RestockRocket.removeInlineForm()when the shopper picks an in-stock variant. selectedVariantIdreads the theme’s add-to-cart form. If your theme keeps the selected variant elsewhere, read it from there.
See the JavaScript API for every argument.
5. React to a signup
Section titled “5. React to a signup”window.addEventListener('stoq:restock-modal:submitted', (event) => { const { variant, customer } = event.detail document.querySelector('.my-notify__button').textContent = 'You’re on the list' // Analytics: one signup for variant.id, by customer.email or customer.phone})stoq:restock-modal:opened and stoq:restock-modal:closed fire too. See Custom events.
If it fails
Section titled “If it fails”| Code | What happened | What to do |
|---|---|---|
invalid_ |
A value failed its check, such as a colour that isn’t #RRGGBB, a position that isn’t auto, float-right, float-left or specific, or an unknown key |
Fix the field named in details[]. and resend |
plan_ |
A paid-only field (inline form, name field, consent, image, branding) on the free plan; nothing was saved | Leave those fields out, or ask the merchant to upgrade |
not_ |
The store has no STOQ settings yet | The merchant opens STOQ once in the Shopify admin to finish setup |
auth_, auth_ |
No API key, or not a current one | Send the store’s key in X-Auth-Token |
On the storefront, nothing returns an error code. If the button does nothing, check in the browser console that window._RestockRocket exists (the app embed is on) and that openModal is called with the product JSON and a variant id of that product.
Check it worked
Section titled “Check it worked”-
GET /back_in_stock/settings/widgetreturns the copy and colours you sent. -
On a draft theme preview, open a product with a sold-out variant, pick it, and press your button: STOQ’s form opens in the new style. Pick an in-stock variant: the button hides.
-
Sign up with a test address, then find the signup:
curl "https://app.stoqapp.com/api/v2/external/back_in_stock/signups?query=test%2Bnotify%40example.com" \-H "X-Auth-Token: $STOQ_API_KEY"It is there (the list returns signups not yet notified by default) with
notified_at: null, theshopify_variant_idyou picked, andsource: "restock-rocket-extension", the storefront form. -
Remove the test signup:
DELETE /back_in_stock/signups/:id.
Thanks for letting us know.
Still stuck? Ask Quinn or chat with support