JavaScript API

STOQ provides a JavaScript API for custom integrations within your Shopify theme. This API is accessible through the window._RestockRocket object when our app loads into your theme.

Available APIs

Page Type
Available APIs

Product Page

openModal, openInlineForm, removeInlineForm, renderButtonForVariant, getSellingPlan

Collection, Home, and Custom Pages

openModal

All pages

marketId

openModal

openModal(productData, variantId, customerData)

Opens the 'Notify me' modal for a specific product. This is typically used for custom elements like quick add buttons.

Parameters:

  • productData (Object): Contains product information

  • variantId (String): ID of the specific variant

  • customerData (Object): Contains customer information (Optional)

Examples:

Opening modal on a collection page:

const addToCartBtn = document.getElementById('quick-add-btn');
addToCartBtn.addEventListener('click', () => {
  const productData = { id: 1111, variants: [{ id: 2222, available: false }] };
  const variantId = '41XX';
  const customerData = { 
    shopify_customer_id: 9999,
    email: '[email protected]',
    phone: '8123999123', // phone number
    country_code: '1', // country code
    country: 'us' // 2 letter ISO country code
  } // Optional
  window._RestockRocket.openModal(productData, variantId, customerData);

  // Alternative: Using Liquid objects directly in Javascript
  // window._RestockRocket.openModal({{ product | json }}, '{{ product.selected_or_first_available_variant.id }}');
});

Opening modal on a product page:

openInlineForm

openInlineForm(productData, variantId, customerData, inlineFormContainer, inlineFormContainerInsertType)

Shows the 'Notify me' modal as an Embedded form for a specific product variant. Use this API to show the Embedded Sign up form in a specific location when an out of stock variant is selected.

Parameters:

  • productData (Object): Contains product information

  • variantId (String): ID of the specific variant

  • customerData (Object): Contains customer information (Optional)

  • inlineFormContainer: Selector for the container where you want to insert the form (Optional)

  • inlineFormContainerInsertType: How the form should be inserted into the container (Optional)

Notes:

  • inlineFormContainer can be passed down in the function call, or you can set it up in-app. Chat with Support to get access to the relevant settings.

  • inlineFormContainerInsertType can be one of: beforebegin, afterbegin, beforeend, afterend. The default is 'beforeend'.

Example:

removeInlineForm

Removes the Embedded form rendered using openInlineForm. Use this API to remove the Embedded Form after a successful submission or when a different variant is selected.

Example:

renderButtonForVariant

renderButtonForVariant(variantId)

Sets up or removes the button for a specific variant on the page. Useful when your theme has a custom variant selector.

Parameters:

  • variantId (String): ID of the variant to render the button for.

Example:

getSellingPlan

getSellingPlan(variantId)

Retrieves the selling plan object for a given variant if a preorder is set up.

Parameters:

  • variantId (String): ID of the variant to check for a selling plan.

Returns:

  • (Object): The selling plan object if found, or null if no preorder is set up for the variant.

Example:

Example Response:

Integration Examples

Quick Add Button on Collection Page

Notify Me Button on Product Page

Custom Integration on Product Page

These examples demonstrate how to integrate RestockRocket's API with buttons using onclick handlers and Shopify Liquid markup. The Liquid examples show how to access product and variant data directly from Shopify, which can then be passed to the RestockRocket API.

Remember to adjust these examples to fit your specific theme structure and requirements.

marketId

This returns the market ID the store is being viewed as:

Last updated