Webhooks
StockrHub uses Shopify webhooks to stay synchronized with your store in real time. Webhooks are HTTP callbacks that Shopify sends to StockrHub whenever specific events occur in your shop.
Registered Webhooks
Section titled “Registered Webhooks”StockrHub listens to the following Shopify webhook topics:
| Webhook Topic | Purpose |
|---|---|
APP_UNINSTALLED | Clean up shop data when the app is uninstalled |
ORDERS_CREATE | Track sales for inventory analytics and sales velocity |
PRODUCTS_UPDATE | Keep product catalog data in sync |
INVENTORY_LEVELS_UPDATE | Sync stock level changes made outside StockrHub |
Webhook Registration
Section titled “Webhook Registration”Webhooks are registered automatically during app installation. When a merchant completes the OAuth flow and installs StockrHub, the app registers all required webhook subscriptions via the Shopify GraphQL Admin API.
mutation webhookSubscriptionCreate($topic: WebhookSubscriptionTopic!, $webhookSubscription: WebhookSubscriptionInput!) { webhookSubscriptionCreate(topic: $topic, webhookSubscription: $webhookSubscription) { webhookSubscription { id topic endpoint { ... on WebhookHttpEndpoint { callbackUrl } } } userErrors { field message } }}Webhook Verification
Section titled “Webhook Verification”Every incoming webhook request is verified before processing to ensure it genuinely came from Shopify.
HMAC Signature Verification
Section titled “HMAC Signature Verification”Shopify signs every webhook payload with an HMAC-SHA256 signature using the app’s client secret. StockrHub verifies this signature on every incoming webhook:
- Extract the signature from the
X-Shopify-Hmac-Sha256header. - Compute the expected HMAC by signing the raw request body with the app’s client secret using HMAC-SHA256.
- Compare signatures using a timing-safe comparison to prevent timing attacks.
- Reject invalid webhooks — if the signatures do not match, the webhook is rejected with a
401 Unauthorizedresponse.
X-Shopify-Hmac-Sha256: <base64-encoded-hmac>Retry Behavior
Section titled “Retry Behavior”If StockrHub fails to process a webhook (returns a non-2xx status code or times out), Shopify will retry the delivery:
- Shopify retries failed webhooks up to 19 times over a 48-hour period.
- Retry intervals increase exponentially (starting at a few seconds, up to several hours).
- If all retries fail, Shopify may automatically remove the webhook subscription.
- StockrHub re-registers any missing webhooks on the next authenticated request from the merchant.
Webhook Data Processing
Section titled “Webhook Data Processing”APP_UNINSTALLED
Section titled “APP_UNINSTALLED”When it fires: A merchant uninstalls StockrHub from their Shopify store.
What StockrHub does:
- Identifies the shop from the webhook payload.
- Removes the shop’s encrypted access token from the database.
- Cleans up shop-specific data (suppliers, POs, reorder rules, settings).
- Logs the uninstall event for analytics.
ORDERS_CREATE
Section titled “ORDERS_CREATE”When it fires: A new order is placed in the Shopify store (from any sales channel).
What StockrHub does:
- Extracts line items from the order payload.
- Records each sold variant and quantity for sales velocity tracking.
- Updates the sales velocity calculations used by the reorder engine.
- Checks if any sold items have fallen below their reorder points and generates alerts if so.
This webhook is critical for the sales velocity report and reorder suggestions features. Without it, StockrHub would not know how fast products are selling.
PRODUCTS_UPDATE
Section titled “PRODUCTS_UPDATE”When it fires: A product is updated in the Shopify admin (title, description, variants, prices, images, etc.).
What StockrHub does:
- Extracts the updated product data from the payload.
- Updates the local product cache in D1 with the latest title, SKU, barcode, and variant information.
- Ensures that product references in purchase orders and reorder rules reflect the current product data.
This keeps StockrHub’s product catalog in sync with Shopify, so that product names, SKUs, and barcodes are always up to date when searching or creating purchase orders.
INVENTORY_LEVELS_UPDATE
Section titled “INVENTORY_LEVELS_UPDATE”When it fires: Inventory levels change for a product variant at a location (from any source — manual adjustments, other apps, POS, etc.).
What StockrHub does:
- Identifies the variant and location from the payload.
- Updates the cached stock level in StockrHub’s database.
- Evaluates the new stock level against any configured reorder rules.
- Generates a low stock alert if the stock has fallen below the reorder point.
Webhook Endpoint
Section titled “Webhook Endpoint”All webhooks are delivered to a single endpoint on the StockrHub app:
POST /webhooksThe endpoint inspects the X-Shopify-Topic header to determine which webhook topic was received and routes the payload to the appropriate handler.
Monitoring and Debugging
Section titled “Monitoring and Debugging”If you suspect webhooks are not being processed correctly:
- Check the Shopify admin under Settings > Notifications > Webhooks to see registered webhooks and their delivery status.
- Review the StockrHub dashboard for any missing or delayed data updates.
- If webhooks appear to be missing, open StockrHub from the Shopify admin — this triggers a re-registration check for any missing webhook subscriptions.