---
title: Webhooks
description: Shopify webhook handler that invalidates Next.js cache tags when products, collections, or CMS metaobjects change.
type: guide
---

# Webhooks



Shopify webhooks make supported Admin changes appear on the storefront without waiting for cached data to expire. The template accepts Shopify notifications at `POST /api/webhooks/shopify` and refreshes the affected product, collection, recommendation, sitemap, or metaobject content.

Webhooks are disabled by default. Without `SHOPIFY_WEBHOOK_SECRET`, the endpoint returns `404` and Shopify changes appear only after cache expiry or a redeploy.

## Set up Shopify webhooks

1. Open **Shopify Admin → Settings → Notifications → Webhooks**.
2. Set the destination to `https://your-domain.com/api/webhooks/shopify`.
3. Choose **JSON** as the format.
4. Register the product, collection, and metaobject topics you need.
5. Copy the webhook signing secret into `SHOPIFY_WEBHOOK_SECRET` for that environment.

```bash
SHOPIFY_WEBHOOK_SECRET="your-webhook-secret-here"
```

Register these supported topics:

* `products/create`, `products/update`, and `products/delete`
* `collections/create`, `collections/update`, and `collections/delete`
* Metaobject create, update, and delete topics

You can register only the topics your store uses. An unregistered topic simply means those changes wait for normal cache expiry.

See [Environment Variables](/docs/reference/env-vars) for the full variable reference.

## Behavior and security

Every configured request must carry a valid Shopify signature. Missing, malformed, or incorrect signatures return `401`. The handler rejects the request before using its topic or payload.

Product notifications refresh the affected product wherever it appears, including recommendations and sitemap content. Product creation and deletion also refresh catalog membership.

Collection notifications refresh the affected collection and collection listings. Collection creation and deletion also refresh collection membership and sitemap content.

Metaobject notifications refresh metaobject-backed content only when your custom reads participate in the template's metaobject invalidation behavior. The base template does not read metaobjects by default.

## Limits

The included handler does not refresh inventory-level changes. Stock updates therefore appear at cache expiry unless another supported product webhook arrives or you add a live inventory strategy.

Shopify does not provide webhook topics for Online Store pages, blogs, articles, or store policies. Those edits rely on cache expiry, a manual purge, or a redeploy. See [Content pages](/docs/anatomy/pages/content) for the current content-page guidance.

Navigation menu edits are also outside this handler.

Malformed product or collection update payloads cannot identify a specific resource, so they do not refresh the full catalog. Valid Shopify deliveries include the expected identifiers.

After registering a topic, use **Send test notification** in Shopify Admin and confirm the delivery succeeds before relying on it for storefront freshness.

## What’s next

Add a topic only when Shopify offers a webhook for the resource and the storefront has a safe way to refresh the affected data. Prefer targeted refreshes for frequently changing catalog data. Use broader refreshes only when an event cannot be scoped or after an intentional bulk change.


---

For a semantic overview of all documentation, see [/sitemap.md](/sitemap.md)

For an index of all available documentation, see [/llms.txt](/llms.txt)

For agent-facing discovery, including API and MCP surfaces, see [/agents.md](/agents.md)