Trigger Zapier Webhooks using Node.js

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

Trigger Zapier Webhooks using Node.js

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.

  • 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

  1. 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.

Create a new Zap

  1. 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.

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

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.

Testing

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

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.

Didn't find this guide useful? Let me know