How it works

Follow these 2 simple steps to start displaying real-time inventory levels by location on your product pages

web request icon

Request

App connector: Web Request • Time to complete: 0 minutes (Auto-configured)
Why this matters: This web request trigger captures the variant ID from your product page when customers want to see inventory levels, starting the entire lookup process.

When someone visits your product page and the inventory check runs, this step receives the variant ID through a query parameter in the URL. The trigger is automatically configured to accept web requests and includes CORS headers to allow cross-origin requests from your storefront. It captures the variant_id from the query string and passes this essential identifier to the next step for inventory lookup. No manual configuration is needed - the trigger handles all incoming requests automatically.

code icon

Custom Code

App connector: Code • Time to complete: 0 minutes (Auto-configured)
Why this matters: This JavaScript code connects to Shopify's GraphQL API to fetch exact inventory quantities for each location where your product variant is stocked.

The custom code takes the variant ID from the previous step and builds a GraphQL query to retrieve inventory levels across all locations. It specifically looks up the product variant, gets its inventory item, and returns the available quantities for each location name. The script uses MESA's built-in Shopify GraphQL connection, so authentication is handled automatically. The response includes location names paired with their available inventory counts, which gets returned as structured JSON data for your frontend to display.

const Mesa = require('vendor/Mesa.js');
const ShopifyGraphql = require('vendor/ShopifyGraphql.js');

/**
 * A Mesa Script exports a class with a script() method.
 */
module.exports = new class {
  script = (payload, context) => {
    let vars = context.steps;
    let variantId = vars.webrequest.querystring.variant_id;
    
    let query = `
      {
        productVariant(id:"gid://shopify/ProductVariant/${variantId}") {
          sku
          inventoryItem {
            inventoryLevels(first:10) {
              nodes {
                location {
                  name
                }
                quantities(names:"available") {
                  available: quantity
                }
              }
            }
          }
        }
      }
    `;

    const r = ShopifyGraphql.send(query, null);

    Mesa.output.next({"response": r.data.productVariant.inventoryItem.inventoryLevels.nodes});
  }
}

Make it your own

Customize this workflow even further:

Filter by specific locations
Modify the GraphQL query to only show inventory from certain store locations, like excluding warehouse stock and only displaying retail locations for customer pickup options.
Add low stock warnings
Extend the script to include conditional logic that flags when inventory drops below a threshold, automatically adding "Low Stock" or "Only X left" messages to your product display.
Cache results for performance
Connect to MESA's data tables to temporarily save inventory data and reduce API calls, especially useful for high-traffic products that get checked frequently throughout the day.
Send inventory alerts
Chain this workflow with email or Slack notifications to alert your team when specific products reach zero inventory at key locations, enabling faster restocking decisions.

Frequently asked questions

Does this work with products that have multiple variants like size and color?
Yes, the workflow looks up inventory for the specific variant ID passed in the request, so each size/color combination will show its own accurate inventory levels across your locations.
What happens if a location has zero inventory?
The GraphQL query will still return that location with a quantity of 0, so you can choose to either display "Out of stock" or hide those locations entirely in your frontend code.
Can I limit which locations appear to customers?
The current workflow shows all locations where the product is tracked, but you can modify the GraphQL query to filter by specific location IDs if you want to exclude warehouses or staff-only locations from customer view.
What is a template?
MESA templates are fully pre-configured workflows built and vetted by Shopify Experts. Unlike competitor templates that provide basic scaffolds requiring extensive setup, MESA templates come with all data variables properly mapped, required fields configured, and steps ready to activate. You can turn them on immediately and start automating.
Can I customize a template?
Absolutely! While our templates work out-of-the-box, every step can be personalized to match your exact business requirements. Add conditional logic, integrate additional apps, or build more sophisticated workflows. MESA's templates provide a solid foundation that you can expand as needed.
Are templates free?
Yes! Our entire library of expert-built, production-ready templates is free to use. Unlike platforms that charge for premium templates or provide only basic scaffolds, MESA gives you access to hundreds of fully-configured, vetted workflows at no additional cost.

Ready to start displaying real-time inventory levels by location on your product pages?

Join thousands who've automated their work and saved an average of 3.5 hours every week.

Start with this template — It's free
7-day free trial • 2 min setup • Cancel anytime