Skip to main content

🚀 Send a notification

Prerequisite

  • A NotificationAPI account - sign up for free
  • A configured notification in the dashboard (new accounts already have a demo notification)

Overview

Your team, even non-technical members, can use our dashboard to configure and design your standard notifications without any coding knowledge. For example, they would configure an alert to go over email and completely design its content, subject, etc.

Then, through our SDKs or API, your back-end lets us know when to send this notification to a user. We then take care of the rest.

Let's learn...

Step 1: Setup the SDK

npm install notificationapi-node-server-sdk
# yarn add notificationapi-node-server-sdk
# pnpm add notificationapi-node-server-sdk

Step 2: Send the Notification

Our send function or POST /sender API call takes a JSON payload that specifies which notification to send and to whom. It also has a mergeTags field that you can use to personalize the notification.

// import/require:
import notificationapi from 'notificationapi-node-server-sdk';
// const notificationapi = require('notificationapi-node-server-sdk').default

// init
notificationapi.init('CLIENT_ID', 'CLIENT_SECRET');

// send
notificationapi.send({
// The ID of the notification you wish to send.
// You can find this value from the dashboard.
notificationId: 'order_tracking',
// The user to send the notification to.
user: {
id: 'spongebob.squarepants',
email: 'spongebob@squarepants.com' //required for email notifications
},
// mergeTags is to pass dynamic values into the notification design.
mergeTags: {
item: 'Krabby Patty Burger',
address: '124 Conch Street',
orderId: '1234567890'
}
});
info

You can get your CLIENT_ID and CLIENT_SECRET from here.

Next Steps

You are now successfully sending notifications to any channel you wish. 🎉

Let's do a few more things: