Hi there, many thanks for your amazing work here;
I'be been trying to wrap my head around webhooks using the provided example. I started by registering a new webhook as follows (I omit less meaningful parts of code with [...], they haven't been changed).
const shopifyConfig = {
host: SHOPIFY_APP_HOST,
[...]
afterAuth(request, response) {
[...]
registerWebhook(shop, accessToken, {
topic: 'orders/create',
address: SHOPIFY_APP_HOST + '/order-create',
format: 'json'
});
},
};
And then use the original example (by manually creating an order, setting it to paid in order to move from "drafted" to "created") to no avail.
app.get('/order-create', withWebhook, (request, response) => {
console.log('We got a webhook!');
console.log('Details: ', request.webhook);
console.log('Body:', request.body);
});
In the console appears a POST to /order-create with an 404 error as a result. Btw, i'm using yarn run start to spin everything, ngrok as a tunnel and everything else is working fine - i have even created some routes of my own - so we can assume auth and express.js are working fine.
It sounds strange to me that a POST request is handled by an app.get
so i changed the code to
app.**post**('/order-create', withWebhook, (request, response) => {
console.log('We got a webhook!');
console.log('Details: ', request.webhook);
console.log('Body:', request.body);
});
Now is a 500 error; but if i drop the "withWebhook"... I get all the JSON data displayed on my console.
app.post('/order-create', (request, response) => {
console.log('We got a webhook!');
console.log('Details: ', request.webhook);
console.log('Body:', request.body);
});
However, deleting the withWebhook feels incorrect and not the way this is supposed to be handled.
Am I missing something?