Shopify provides webhooks for stores. What is a webhook?
Webhooks are a useful tool for apps that want to execute code after a specific event happens on a shop, for example, after a customer creates a cart on the storefront, or a merchant creates a new product in their admin.
So let’s say we want to notify a fulfilment house (to process and ship our product) as soon as a new order is created on our Shopify store. The fulfilment house may have a very specific format in which they accept an order. So we could write a script that takes the data that Shopify sends us after an order is made, re-format it for the 3rd party, and then do a POST request to them.
There are a few steps to get this done.
Setup the webhook on Shopify
First.. we need to setup a webhook on our Shopify store that calls our script everytime an order is made.
Then we need to select which event we want to trigger for our server to be called. In this example it’ll be “Order creation”.
For the URL, we need:
- the domain name or IP address of the server. In this case the fictitious IP address is
- our Node.js server might be running on a specific port, in this case
- and then for what path we want in our script to start processing the incoming webhook. In this case it will be
Setting up our script
Secondly, we’ll setup a Node.js server to process the incoming new order data sent from Shopify.
You’ll need Node.js setup on your server. I use DigitalOcean. To manually setup Node.js on Ubuntu 16.04 see this guide. Alternatively, DigitalOcean has a one-click install option for Node.js when creating a droplet with them.
The core code looks like this:
The only thing you need to change to get started is on line 31 change the path to /new-online-order and the port on line 40 to 5555.
You can then run this on your server by typing
Create a new order, and you should see this node server
console.log a bunch of Shopify data. In this case, it’ll be the new order object where the properties are defined in the Order API.
Where to from here?
Basically just start writing out your script from line 37 in the gist. You can process the data anyway you like, and email it, post it or do anything else you like from there.
Any questions at all, just ask them below.
Have fun with it!