Skip to content

[2023-04-04] Nylas Node.js SDK v6.10.0

The Nylas Node.js SDK v6.10.0 has been released!

Added

This latest release of the Nylas Node SDK includes support for verifying webhook signatures.(#442)

Verifying a webhook signature with the Nylas Node.js SDK

const Nylas = require("nylas");
const express = require("express");
const cors = require("cors");
const app = express();
// Enable CORS
app.use(cors());
// The port the express app will run on
const port = 9000;
// Nylas app credentials
const NYLAS_CLIENT_SECRET = process.env.NYLAS_CLIENT_SECRET;
if (!NYLAS_CLIENT_SECRET) {
throw new Error("NYLAS_CLIENT_SECRET is required");
}
// Create a callback route for the Nylas Event Webhook
app.post("/", express.json(), async (req, res) => {
// Verify the Nylas Event Webhook signature to ensure the request is coming from Nylas
const signature =
req.headers["x-nylas-signature"] || req.headers["X-Nylas-Signature"];
if (
!WebhookNotification.verifyWebhookSignature(
NYLAS_CLIENT_SECRET,
signature,
JSON.stringify(req.body)
)
) {
res.status(403).send("Invalid signature");
}
const { body } = req;
// Log the webhook event to the console
console.log("Webhook event received: ", JSON.stringify(body, undefined, 2));
// Send a 200 response to the Nylas Event Webhook
res.status(200).send({ success: true });
});