Grow your SaaS organically with Content Marketing.
Try for free →In this guide, we will trigger a Zapier Webhook event to trigger an action using Axios and Node.js.
Zapier is a great automation tool that can one application to another seamlessly. Take advantage of the massive list of integrations Zapier provides access to and trigger workflows when certain actions occur within your application.
Create a new Zapier account here. The Webhook trigger event is only available starting from the Starter plan so make sure you either have an active subscription or using the Free Trial.
Catch Hook
. This will let us a send a POST request from our application that we can trigger an action off with.Now that the Zapier side is set up, we need to trigger it using Node.js when a relevant event occurs in our application.
We can create a zapier.js
file that keeps all the Zapier related logic in there. The notifyWebhook
function will make a POST request to the URL provided with the body specified.
// using axios
const axios = require("axios");
export const notifyWebhook = async (url, body) => {
const res = await axios.post(url, body, {
Accept: "application/json",
"Content-Type": "application/json",
});
};
// using fetch
export const notifyWebhook = async (url, body) => {
const res = await fetch(url, {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
body: JSON.stringify({ body }),
});
console.log(res.json());
};
We can use this function in our application now when a notable event occurs. Notice the URL is the **Custom Webhook URL **Zapier generated from us.
notifyWebhook("<https://hooks.zapier.com/hooks/catch/9539273/bds3d2n>", {
user: "saasbase",
message: "Trigger Webhook event",
});
This will send an event with the specified body.
Ensure that setup is working correctly by making the first request and testing the trigger. You should see your message body show up.
Once the trigger is set up, we can connect an action that will run. As an example, the Gmail action will send me an email with the body message formatted in a human-readable way.
Trigger Zapier Webhooks using Node.js
I'm building a new SaaS to automate content marketing for your SaaS
Tools for SaaS Devs