API reference for the @novu/js package

Complete API reference for the Novu JavaScript package

Novu

The Novu client provides methods to interact with notifications, preferences, and real-time events.

Constructor Options

PropTypeDefault
useCache?
boolean
-
socketUrl?
string
-
apiUrl?
string
-
backendUrl?
string
-
subscriberHash?
string
-
subscriberId?
string
-
applicationIdentifier?
string
-

Usage

import { Novu } from "@novu/js";
 
const novu = new Novu({
  subscriberId: "SUBSCRIBER_ID",
  applicationIdentifier: "APPLICATION_IDENTIFIER",
});

Notifications

Methods

list

Fetches a list of notifications based on provided filters.

PropTypeDefault
archived?
boolean
-
read?
boolean
-
tags?
string[]
-
const notifications = await novu.notifications.list({
  limit: 30,
  read: false,
  archived: false,
  tags: ['tag1', 'tag2'],
  offset: 0,
});

The response will be of type:

PropTypeDefault
filter?
NotificationFilter
-
hasMore?
boolean
-
notifications?
Notification[]
-

count

Fetches the count of notifications based on filters.

PropTypeDefault
archived?
boolean
-
read?
boolean
-
tags?
string[]
-
// Single filter
const count = await novu.notifications.count({
  read: false,
  archived: false,
});

read

Marks a notification as read.

await novu.notifications.read({ notificationId: 'NOTIFICATION_ID' });

unread

Marks a notification as unread.

await novu.notifications.unread({ notificationId: 'NOTIFICATION_ID' });

archive

Archives a notification.

await novu.notifications.archive({ notificationId: 'NOTIFICATION_ID' });

unarchive

Unarchives a notification.

await novu.notifications.unarchive({ notificationId: 'NOTIFICATION_ID' });

readAll

Marks all notifications as read. Can be filtered by tags.

await novu.notifications.readAll({
  tags: ['tag1', 'tag2'],
});

archiveAll

Archives all notifications. Can be filtered by tags.

await novu.notifications.archiveAll({
  tags: ['tag1', 'tag2'],
});

archiveAllRead

Archives all read notifications. Can be filtered by tags.

await novu.notifications.archiveAllRead({
  tags: ['tag1', 'tag2'],
});

completePrimary

Marks primary action of a notification as completed.

await novu.notifications.completePrimary({ notificationId: 'NOTIFICATION_ID' });

completeSecondary

Marks secondary action of a notification as completed.

await novu.notifications.completeSecondary({ notificationId: 'NOTIFICATION_ID' });

revertPrimary

Reverts primary action of a notification to pending.

await novu.notifications.revertPrimary({ notificationId: 'NOTIFICATION_ID' });

revertSecondary

Reverts secondary action of a notification to pending.

await novu.notifications.revertSecondary({ notificationId: 'NOTIFICATION_ID' });

Preferences

Methods

list

Fetches the subscriber's notification preferences.

const preferences = await novu.preferences.list();

The response will be of type:

PropTypeDefault
workflow?
Workflow
-
overrides?
IPreferenceOverride[]
-
channels?
ChannelPreference
-
enabled?
boolean
-
level?
PreferenceLevel
-

Events

The Novu client provides real-time event handling through WebSocket connections.

Available Events

  • notifications.notification_received: Triggered when a new notification is received
  • notifications.unread_count_changed: Triggered when the unread count changes

Usage

novu.on('notifications.notification_received', (data) => {
  console.log('New notification:', data);
});
 
novu.on('notifications.unread_count_changed', (data) => {
  console.log('Unread count:', data);
});

Types

Notification

PropTypeDefault
off?
<Key extends EventNames>(eventName: Key, listener: EventHandler<Events[Key]>) => void
-
on?
<Key extends EventNames>(eventName: Key, listener: EventHandler<Events[Key]>) => () => void
-
revertSecondary?
() => Result<Notification, NovuError>
-
revertPrimary?
() => Result<Notification, NovuError>
-
completeSecondary?
() => Result<Notification, NovuError>
-
completePrimary?
() => Result<Notification, NovuError>
-
unarchive?
() => Result<Notification, NovuError>
-
archive?
() => Result<Notification, NovuError>
-
unread?
() => Result<Notification, NovuError>
-
read?
() => Result<Notification, NovuError>
-
data?
Record<string, unknown>
-
redirect?
Redirect
-
tags?
string[]
-
channelType?
ChannelType
-
secondaryAction?
Action
-
primaryAction?
Action
-
avatar?
string
-
archivedAt?
string
-
readAt?
string
-
createdAt?
string
-
isArchived?
boolean
-
isRead?
boolean
-
to?
Subscriber
-
body?
string
-
subject?
string
-
id?
string
-

Action

PropTypeDefault
redirect?
Redirect
-
isCompleted?
boolean
-
label?
string
-

NotificationButton

PropTypeDefault
SECONDARY?
NotificationButton.SECONDARY
-
PRIMARY?
NotificationButton.PRIMARY
-

Subscriber

PropTypeDefault
subscriberId?
string
-
avatar?
string
-
lastName?
string
-
firstName?
string
-
id?
string
-

On this page