Topics covering webhook creation & management, event handling, Pub/Sub, and Eventbridge, in Shopify apps.
So I'm trying to setup a webhook for order creation but, turns out every time we create an order we receive the following response:
{ request:{ method:'POST', url:'/api/webhook/order/creation', header:{ host:'oururl.com', 'x-real-ip':'35.237.35.110', 'x-forwarded-for':'35.237.35.110', 'x-forwarded-proto':'https', connection:'close', 'content-length':'6234', 'user-agent':'Shopify-Captain-Hook', accept:'*/*', 'accept-encoding':'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'content-type':'application/json', 'x-shopify-api-version':'2019-04', 'x-shopify-hmac-sha256':'r/69+XDBikIlpLJ+DulAUOXxkHhz2m+ZjL99YZeYHsE=', 'x-shopify-order-id':'974194835492', 'x-shopify-shop-domain':'customshop.myshopify.com', 'x-shopify-test':'true', 'x-shopify-topic':'orders/create' } }, response:{ status:404, message:'Not Found', header:[ Object:null prototype ] { vary:'Origin' } }, app:{ subdomainOffset:2, proxy:false, env:'development' }, originalUrl:'/api/webhook/order/creation', req:'<original node req>', res:'<original node res>', socket:'<original node socket>' }
and this is the actual code for the webhook receiver:
require('isomorphic-fetch'); const Router = require('koa-router'); const router = new Router(); const {SHOPIFY_API_SECRET_KEY} = process.env; const {receiveWebhook} = require('@shopify/koa-shopify-webhooks'); const webhook = receiveWebhook({secret: SHOPIFY_API_SECRET_KEY}); router.post('/api/webhook/order/creation', webhook, (ctx) => { console.log('received webhook: ', ctx.state.webhook); }); module.exports = router;
I need help soon!
Solved! Go to the solution
This is an accepted solution.
My apologies in advance, but I'm having trouble understanding what exactly you mean by:
The 404 error is the one we receive from Shopify webhooks (order creation), we've tried different topics but the problem is the same.
Are you saying you're having problems creating these webhooks? Going off the payload you shared, it seems like you're actually referring to the POST request we make to your app as part of the webhook firing process, but Shopify wouldn't be returning a 404 to you when it's the one making the POST request. Looking at webhook logs on my end, they appear to be getting delivered successfully, so I must be misunderstanding something.
To be clear, are you saying that you are returning a 404 to Shopify, or can you break it down for me a bit more?
Cheers.
Alex | Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit the Shopify Help Center or the Shopify Blog
Does posting to your router manually with something like curl work? And to be clear, your app is what's responding with a 404 to Shopify webhooks?
I can take a look at some logs if you provide me with an X-Request-Id response header that you receive from the event triggering the webhook, so in this case, the order creation request.
Cheers.
Alex | Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit the Shopify Help Center or the Shopify Blog
Our server is working just fine if that's what you meant, is currently in use in production.
The 404 error is the one we receive from Shopify webhook (order creation), we've tried different topics but the problem is the same.
And shopify isn't sending that header you requested, we only receive the ones I posted within the question.
Thanks!
Our server is working just fine if that's what you meant, is currently in use in production.
The 404 error is the one we receive from Shopify webhooks (order creation), we've tried different topics but the problem is the same.
And shopify isn't sending that header you requested, we only receive the ones I posted within the question.
Thanks!
This is our most recent webhook payload sent by shopify if that helps:
{ request: { method: 'POST', url: '/webhooks/products/create', header: { host: '8aa7c954.ngrok.io', 'user-agent': 'Shopify-Captain-Hook', 'content-length': '1033', accept: '*/*', 'accept-encoding': 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'content-type': 'application/json', 'x-shopify-api-version': '2019-04', 'x-shopify-hmac-sha256': 'lb3VDjfAKlIkfRwtyV8l1cJvTquAnO6q5y5IvcxMyS4=', 'x-shopify-product-id': '1295576236068', 'x-shopify-shop-domain': 'shoptimizedneuenstore2.myshopify.com', 'x-shopify-topic': 'products/create', connection: 'close', 'x-forwarded-proto': 'https', 'x-forwarded-for': '35.196.79.203' } }, response: { status: 404, message: 'Not Found', header: [Object: null prototype] { vary: 'Origin' } }, app: { subdomainOffset: 2, proxy: false, env: 'development' }, originalUrl: '/webhooks/products/create', req: '<original node req>', res: '<original node res>', socket: '<original node socket>' }
This is an accepted solution.
My apologies in advance, but I'm having trouble understanding what exactly you mean by:
The 404 error is the one we receive from Shopify webhooks (order creation), we've tried different topics but the problem is the same.
Are you saying you're having problems creating these webhooks? Going off the payload you shared, it seems like you're actually referring to the POST request we make to your app as part of the webhook firing process, but Shopify wouldn't be returning a 404 to you when it's the one making the POST request. Looking at webhook logs on my end, they appear to be getting delivered successfully, so I must be misunderstanding something.
To be clear, are you saying that you are returning a 404 to Shopify, or can you break it down for me a bit more?
Cheers.
Alex | Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit the Shopify Help Center or the Shopify Blog
Turns out the issue was the body parser middleware breaking everything. Apologies!
Feel free to remove this issue, looks pointless.
Cheers!
Hey can you share the issue and solution for the body parser you found.
We are doing it this way it works for most but failing for some specific calls.