Back to APIs

Automate sending notifications across multiple channels.

Using the Novu API with Trigger.dev

You can use Trigger.dev with any existing Node SDK or even just using fetch. Using io.runTask makes your Novu background job resumable and appear in our dashboard.

Use io.runTask() and the official SDK or fetch.

Use our HTTP endpoint to subscribe to webhooks

Example code using Novu

Below are some working code examples of how you can use Novu with Trigger.dev. These samples are open source and maintained by the community, you can copy and paste them into your own projects.

1
import z from "zod";
2
import { Novu } from "@novu/node";
3
import { TriggerClient, eventTrigger } from "@trigger.dev/sdk";
4
5
// Get your API key from https://web.novu.co/settings
6
const novu = new Novu(process.env.NOVU_API_KEY!);
7
8
// Using official SDK kit: https://docs.novu.co/sdks/nodejs
9
client.defineJob({
10
id: "create-novu-subscriber",
11
name: "Create Novu subscriber",
12
version: "1.0.0",
13
trigger: eventTrigger({
14
name: "create-novu-subscriber",
15
schema: z.object({
16
subscriberId: z.string(),
17
avatar: z.string().optional(),
18
email: z.string().email().optional(),
19
firstName: z.string().optional(),
20
lastName: z.string().optional(),
21
locale: z.string().optional(),
22
phone: z.string().optional(),
23
data: z.record(z.string(), z.any()).optional(),
24
}),
25
}),
26
run: async (payload, io) => {
27
await io.runTask(
28
"Create subscriber",
29
async () => {
30
const subscriber = await novu.subscribers.identify(
31
payload.subscriberId,
32
{
33
avatar: payload.avatar,
34
email: payload.email,
35
firstName: payload.firstName,
36
lastName: payload.lastName,
37
locale: payload.locale,
38
phone: payload.phone,
39
data: payload.data,
40
}
41
);
42
43
return subscriber.data;
44
},
45
46
// Add metadata to improve how the task displays in the logs
47
{ name: "Create subscriber", icon: "novu" }
48
);
49
},
50
});