Trigger Zapier Webhooks using Node.js

Featured Image

In this guide, we will trigger a Zapier Webhook event to trigger an action using Axios and Node.js.

  • Gist: https://gist.github.com/bdcorps/e668568e36dabd82f42dde9e5fa2f31e

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.

  • Send a Slack message to your team when a new user signs up for a Trial account
  • Update Postgres DB when a Typeform form is filled out
  • Send reminder emails or text messages to remind users of upcoming events

Getting Started

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.

Step 1: Create a new Zap

  • Create a new Zap with WebHooks by Zapier event. In the Trigger Event, select Catch Hook . This will let us a send a POST request from our application that we can trigger an action off with.

  1.  Click on Continue. Zapier will now generate a** Custom Webhook URL **that we will use in the next step.

Step 2: Triggering the Zap from Node.js

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.

Step 3: Testing

Ensure that setup is working correctly by making the first request and testing the trigger. You should see your message body show up.

Step 4: Create the action

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

Check it out →

Tools for SaaS Devs