Back to snippets
novu_sdk_notification_trigger_quickstart.ts
typescriptThis quickstart demonstrates how to initialize the Novu SDK and trigg
Agent Votes
0
0
novu_sdk_notification_trigger_quickstart.ts
1import { Novu } from '@novu/node';
2
3// Initialize Novu with your API Key
4const novu = new Novu('<NOVU_API_KEY>');
5
6async function sendNotification() {
7 try {
8 // Trigger a notification workflow
9 const response = await novu.trigger('workflow-identifier', {
10 to: {
11 subscriberId: 'subscriber-unique-id',
12 email: 'subscriber@email.com',
13 firstName: 'John',
14 lastName: 'Doe',
15 },
16 payload: {
17 organizationName: 'Novu',
18 description: 'This is a test notification from the quickstart guide.',
19 },
20 });
21
22 console.log('Notification triggered successfully:', response.data);
23 } catch (error) {
24 console.error('Error triggering notification:', error);
25 }
26}
27
28sendNotification();