Skip to content

Instantly share code, notes, and snippets.

@magician11
Created November 21, 2016 08:06
Show Gist options
  • Save magician11/08a226555161d633e21fc2bcf374e708 to your computer and use it in GitHub Desktop.
Save magician11/08a226555161d633e21fc2bcf374e708 to your computer and use it in GitHub Desktop.
How to listen to Shopify webhook event data with Node.js
/* eslint-disable no-console */
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
/*
Shopify issues a HTTP POST request.
- https://help.shopify.com/api/tutorials/webhooks#receive-webhook
*/
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true,
}));
/*
In your Shopify store under..
Settings->Notifications
Click "Create a webhook"
- Choose your event
- Leave the format as JSON
- set the URL with your IP address to your server so it's something like http://123.345.11.22:3800/your-path
Then update the path "your-path" below to match, as well as the port number below.
*/
app.post('/your-path', (req, res) => {
// let Shopify know we received the order details ok
res.send('OK');
// the body of the data received
const theData = req.body;
console.log(theData);
});
const portToListenOn = 3800;
/*
On your server run
node listen-for-shopify-webhooks.js
*/
app.listen(portToListenOn, () => {
console.log(`Listening for Shopify webhook event data on port ${portToListenOn}. Started ${new Date().toString()}`);
});
@louischausse
Copy link

In fact, it seems a good way to listen to every webhook! Thanks!

@mohammedazfersheikh
Copy link

can you tell me how can i send theData to front end?

@magician11
Copy link
Author

can you tell me how can i send theData to front end?

Well subscribing to webhooks sends the payload to a server.

Depending on your what you're trying to do, I'd try and get the data directly from the frontend. If they only way the front-end data can get this data is by waiting for the server to receive it, then you could write that data to a database like Firestore, and have your front-end listen for changes to that database.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment