Now, I’ve configured everything, but webhook delivery fails with a 404 error according to the Partner Dashboard. The Cloudflare tunnel is correctly set up, and the console logs show no errors.
Here’s my setup:
Webhook Endpoint in index.js
app.post('/webhooks', express.text({ type: '*/*' }), async (req, res) => {
const { valid, topic, domain } = await shopify.api.webhooks.validate({
rawBody: req.body,
rawRequestBody: req,
rawResponse: res,
});
if (!valid) {
console.error('Invalid webhook signature');
return res.status(400).send('Invalid webhook signature');
}
if (topic === 'orders/create' || topic === 'orders/updated') {
console.log('Order updated');
}
res.status(200).send('Webhook received');
});
Shopify App Initialization
const shopify = shopifyApp({
api: {
apiVersion: LATEST_API_VERSION,
restResources,
billing: billingConfig,
},
auth: {
path: '/api/auth',
callbackPath: '/api/auth/callback',
},
webhooks: {
path: '/webhooks',
webhooks: [
{
topic: 'orders/create',
deliveryMethod: DeliveryMethod.Http,
callbackUrl: '/webhooks',
},
{
topic: 'orders/updated',
deliveryMethod: DeliveryMethod.Http,
callbackUrl: '/webhooks',
},
],
},
hooks: {
afterAuth: async ({ session }) => {
await shopify.registerWebhooks({ session });
},
},
sessionStorage: new SQLiteSessionStorage(DB_PATH),
});
shopify.app.toml
[access_scopes]
# Learn more at https://shopify.dev/docs/apps/tools/cli/configuration#access_scopes
scopes = "read_customer_events,read_customers,read_orders,write_orders,write_pixels,write_products"
[auth]
redirect_urls = [
"https://volunteers-corner-monsters-skins.trycloudflare.com/auth/callback",
"https://volunteers-corner-monsters-skins.trycloudflare.com/auth/shopify/callback",
"https://volunteers-corner-monsters-skins.trycloudflare.com/api/auth/callback"
]
[webhooks]
api_version = "2024-10"
[[webhooks.subscriptions]]
topics = [ "orders/updated" ]
uri = "/webhooks"
Despite this setup, the webhook requests fail with a 404 error. I’ve verified that the webhook URL is the same as the Cloudflare tunnel URL and matches the application_url
in shopify.app.toml
. The app runs without errors, but webhook requests never reach the /webhooks
endpoint.
Here’s a screenshot of the Partner Dashboard showing the webhook failures:
Steps I’ve Taken
- Verified the Cloudflare tunnel URL is correct.
- Confirmed the
/webhooks
endpoint exists.
- Checked the Partner Dashboard, which indicate a 404 error(in the previous setup I got 503).
- Logged incoming requests to the
/webhooks
endpoint, but nothing is received.
I’ve been stuck on this issue for over two weeks. Could someone help me debug or spot what I might be missing? Any advice would be greatly appreciated!
PS: I sent a post request to my other app endpoint (/api/orders/sync
) via tunnel URL, and it hit the endpoint. But when I sent it using webhook route /webhooks
it didn’t even hit the endpoint
Then I changed my webhook URL endpoint to /api/webhooks
Then I received the the post request with this error:
10:43:50 │ web-backend │ [shopify-api/INFO] Receiving webhook request
10:43:50 │ web-backend │ [shopify-app/ERROR] Failed to process webhook: Error: No HTTP webhooks registered for topic ORDERS_UPDATED