Articles on: Notifications

How to Send Notifications Using API Requests?

If you want to send WhatsApp messages to your customers from 3rd party websites, apps or using automation tools like Zapier or Pabbly, you can do that using our API feature.

All you need to do is create a Notification with type Transactional and select a message template that you want to send. Then you get a unique API endpoint URL to which you can send requests to trigger this notification and send the message.

Note: This is an advanced feature so you might need help of your developer to set this up for you if you’re not familiar with using REST API, JSON data, webhook URL etc.

Here are the exact steps involved to do the setup:

Step 1 - Create a Transactional Notification



Create a Notification and select Type as Transactional.
Then from the Trigger dropdown, select the API request to a Webhook URL option.
Then select your Message template that you want to send.



Step 2 - Setup Webhook URL & Request Data



After doing the above steps you will see the Webhook URL for this notification. You need to send POST request to this URL with recipient contact information and template specific variable data to trigger the notification.

Sending request to this URL does two things: add contact to your Contacts and send the message template to that contact.

You can send the request data in one of two ways as shown under the Webhook Request Data Format options:

1. Default


With this option you'll get a default request data in JSON format. This JSON is dynamic and is generated according to the selected Message Template. When you send request in this format to the URL with your custom data, the notification will get triggered.



The JSON has two main parts data and recipients.

The data part contains the variables and is dynamically generated as per the selected Message Template. If your template does not have variables, you'll not see this part in the JSON.
The recipients part is where you add your recipient's phone number, first name, last name, contact list name, tags etc. The data added here is first saved as a Contact and then the Notification is sent to this contact. If the contact does not exist, a new contact is created. But if the contact already exists, the request simply updates the contact and it's other data.

A few important notes:

You have to only add values and the keys should not be changed. The only key you can change is the attribute keys custom_attribute_1, custom_attribute_2 etc as per your attribute names.
You need to save the Notification first before you can start sending requests to the Webhook URL.

This Default option for sending requests is best if you have full control over the website/app from where you'll be triggering the notification. Usually this would be your custom code for making POST requests. If your website/app does not support sending requests with JSON like this, you can choose the Custom option below instead.

2. Custom


If you want to send trigger notification from a website or automation tool that sends data in it's own JSON format or only supports key value pairs for sending request, then you need to select this option.

You can set this up in 3 simple steps:

Step 1 - Save this notification and come back down to this section.



Step 2 - Click on the Listen to incoming request button and send sample POST request to the given Webhook URL from your website, app or automation tool in JSON format. In this step we try to recognize the structure of your sample data and fetch all the available keys. You can send the data in any format from simple key-value pairs to complex array structure. The only requirement is it should be in JSON.



Step 3 - Map the request data fields with fields needed in this notification and save this notification. On left column you'll find the required Message Template variable fields and the Recipient contact fields. On the right column you can select the keys form your sample request that'll be passed to these fields during the actual request. Once you've mapped all the fields click on the Save button.



Once this is done, you can move to the next step.

Step 3 - Trigger Notification to Send Message



After your Notification is created, it's status will show as On-going. This tells us that this Notification is always on and will run each time you make the API request to the Webhook URL.

So the final step is to configure the URL and request on your end. It can either be in your custom code in your website/app or on a 3rd party tool like Zapier, Pabbly etc using their API Request actions.

We've made it super easy for anyone to trigger notifications using our API feature. Do try it out on your end. If you face any issues or challenges during the setup, feel free to reach out to us using our website chat widget.

Updated on: 12/01/2024

Was this article helpful?

Share your feedback

Cancel

Thank you!