Skip to main content

Using API to Send Notifications

In the previous chapter, we learned how to send a notification directly from the Engagespot dashboard. But that is not always the best solution. In most cases, notifications should be sent programatically from your code.

For example, if you're building a social network and you want to notify your users when another user comments on their photo, you need to integrate Engagespot API in your program, right?

Well, luckily, it's simple. Let's quickly learn how to send the below notification via Engagespot REST API.

img

warning

Before you try to send notifications via the REST API, make sure you're authenticating your app users with Engagespot via front-end integration. Read Quick start guide for Javascript, or Android/iOS to learn more.

Notifications sent to a recipient who has not yet identified by Engagespot will be discarded.

Consuming the REST API

To send notifications, you should send a POST request to https://api.engagespot.co/v3/notifications API with the following details.

var axios = require('axios');

axios.post(
'https://api.engagespot.co/v3/notifications',
{
notification: {
title: 'Rose accepted your friend request',
},
recipients: ['[email protected]'],
},
{
headers: {
'X-ENGAGESPOT-API-KEY': 'YOUR_ENGAGESPOT_API_KEY',
'X-ENGAGESPOT-API-SECRET': 'YOUR_ENGAGESPOT_API_SECRET',
},
}
);

Where recipients is the list of users who should receive this notification. Wondering how Engagespot identifies your users? Remember you had passed the email-id (or any unique id) of your users in the front-end SDK? That's how Engagespot identifies your users and sends the notification to them, no matter how many devices they are using.

Detailed API Guide

There are other parameters you can pass to this send Notification API. You can learn more about them from the REST API reference page.