-
Notifications
You must be signed in to change notification settings - Fork 18
Node API integration example: Part 2
Steve Astels edited this page Sep 4, 2020
·
2 revisions
// index.js
/**
* External Modules
*/
const express = require("express");
const NotifyClient = require("notifications-node-client").NotifyClient;
/**
* App Variables
*/
const app = express();
const port = "8000";
const notifyClient = new NotifyClient(
"https://api.staging.notification.cdssandbox.xyz/",
process.env.NOTIFY_API_KEY
);
/**
* Routes
*/
app.get("/", (req, res) => {
notifyClient
.sendEmail("your colour template id", "your email address", {
personalisation: { colour: "purple" },
reference: "",
})
.then((response) => {
console.log("Purple email sent");
res.status(200).send("Purple email sent");
})
.catch((err) => {
console.error(err);
res.status(500).send("Fail");
});
});
/**
* Server Activation
*/
app.listen(port, () => {
console.log(`Listening to requests on http://localhost:${port}`);
});