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
| Prop | Type | Default |
|---|---|---|
subscriber? | string | Subscriber | - |
subscriberId? | string | - |
context? | Partial<Record<string, ContextValue>> | - |
defaultSchedule? | DefaultSchedule | - |
useCache? | boolean | - |
socketUrl? | string | - |
apiUrl? | string | - |
contextHash? | string | - |
subscriberHash? | string | - |
applicationIdentifier? | string | undefined | - |
backendUrl? | string | - |
Usage
Notifications
Methods
list
Fetches a list of notifications based on provided filters.
| Prop | Type | Default |
|---|---|---|
severity? | SeverityLevelEnum | SeverityLevelEnum[] | - |
data? | Record<string, unknown> | - |
seen? | boolean | - |
snoozed? | boolean | - |
archived? | boolean | - |
read? | boolean | - |
tags? | string[] | - |
The response will be of type:
| Prop | Type | Default |
|---|---|---|
filter? | NotificationFilter | - |
hasMore? | boolean | - |
notifications? | Notification[] | - |
count
Fetches the count of notifications based on filters.
| Prop | Type | Default |
|---|---|---|
severity? | SeverityLevelEnum | SeverityLevelEnum[] | - |
data? | Record<string, unknown> | - |
seen? | boolean | - |
snoozed? | boolean | - |
archived? | boolean | - |
read? | boolean | - |
tags? | string[] | - |
read
Marks a notification as read.
unread
Marks a notification as unread.
seen
Marks a notification as seen.
Seen vs Read: Notifications can be "seen" (automatically tracked when visible) or "read" (explicitly marked by user interaction). The Inbox component automatically marks notifications as seen when they're visible for 1+ seconds using the browser's IntersectionObserver API. This automatic tracking batches requests for performance and works seamlessly with infinite scroll and pagination, while read status requires explicit user action.
Why no unseen method? Unlike read/unread which can be toggled, seen is designed as a one-way operation. Once a notification has been seen by a user, it remains seen. This reflects the natural user experience where visibility cannot be "undone". Use filtering with seen: false to get unseen notifications instead.
seenAll
Marks notifications as seen. You can filter them by notification IDs, tags, or data attributes.
archive
Archives a notification.
unarchive
Unarchives a notification.
readAll
Marks all notifications as read. You can filter them by tags.
archiveAll
Archives all notifications. You can filter them by tags.
archiveAllRead
Archives all read notifications. You can filter them by tags.
delete
Deletes a single notification permanently.
deleteAll
Deletes multiple notifications permanently. You can filter them by tags or data attributes.
snooze
Snoozes a notification for a specified duration. Here snoozeUntil is ISO 8601 formatted string timestamp, representing the date and time the notification is un-snoozed, it should be a future date and time.
unsnooze
Unsnoozes a notification.
completePrimary
Marks primary action of a notification as completed.
completeSecondary
Marks secondary action of a notification as completed.
revertPrimary
Reverts primary action of a notification to pending.
revertSecondary
Reverts secondary action of a notification to pending.
Notification
Individual notification instances have their own methods for marking as seen, read, archived, etc. These methods are available directly on each notification object.
Methods
seen()- Marks the notification as seenread()- Marks the notification as readunread()- Marks the notification as unreadarchive()- Archives the notificationunarchive()- Unarchives the notificationdelete()- Deletes the notificationsnooze()- Snoozes the notificationunsnooze()- Unsnoozes the notificationcompletePrimary()- Marks primary action as completedcompleteSecondary()- Marks secondary action as completedrevertPrimary()- Reverts primary action to pendingrevertSecondary()- Reverts secondary action to pending
seen() method is only available on individual notification instances, not on the novu.notifications object. Use novu.notifications.seenAll() for bulk operations.Usage
Preferences
Methods
list
Fetches the subscriber's notification preferences.
update
update method is available with each preference object.
The response will be of type:
| Prop | Type | Default |
|---|---|---|
schedule? | { isEnabled: boolean; weeklySchedule?: WeeklySchedule | undefined; } | - |
workflow? | Workflow | - |
overrides? | IPreferenceOverride[] | - |
channels? | ChannelPreference | - |
subscriptionId? | string | - |
condition? | RulesLogic | - |
enabled? | boolean | - |
level? | PreferenceLevel | - |
bulkUpdate
Updates multiple workflow's channel preferences at once.
Schedule
The preferences.schedule submodule lets you fetch and update a subscriber’s delivery schedule.
get
Fetches the subscriber’s schedule.
update
Updates the subscriber’s schedule. You can update the entire weekly schedule or only specific days.
Schedule Class
A Schedule instance is returned when fetching or updating a schedule.
| Prop | Type | Default |
|---|---|---|
update? | (args: UpdateScheduleArgs) => Result<Schedule> | - |
weeklySchedule? | WeeklySchedule | undefined | - |
isEnabled? | boolean | undefined | - |
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.notifications.unseen_count_changed: Triggered when the unseen count changes.preferences.schedule.get.pending: Triggered when fetching a schedule starts.preferences.schedule.get.resolved: Triggered when fetching a schedule succeeds.preferences.schedule.update.pending: Triggered when updating a schedule starts.preferences.schedule.update.resolved: Triggered when updating a schedule succeeds.subscriptions.list.pending: Triggered when loading subscriptions starts.subscriptions.list.resolved: Triggered when subscriptions are loaded.subscriptions.get.pending: Triggered when fetching a subscription starts.subscriptions.get.resolved: Triggered when a specific subscription is fetched.subscriptions.create.pending: Triggered when creating a subscription starts.subscriptions.create.resolved: Triggered when a subscription is created.subscriptions.update.pending: Triggered when updating a subscription starts.subscriptions.update.resolved: Triggered when a subscription is updated.subscriptions.delete.pending: Triggered when deleting a subscription start.subscriptions.delete.resolved: Triggered when a subscription is deleted.
Usage
Subscriptions
The Subscriptions module lets you manage a subscriber’s subscriptions to topics. A subscription represents a subscriber’s opt-in to a topic and defines which workflows within that topic they receive notifications from.
It supports creating conditional subscriptions where users only receive notifications if specific criteria (payload filters) are met.
Manage subscriptions at two levels:
- Module-level methods on
novu.subscriptions - Instance-level methods on a
TopicSubscriptionobject
Methods
List
Fetches all subscriptions for a specific topic.
| Prop | Type | Default |
|---|---|---|
topicKey? | string | - |
The response items are TopicSubscription instances.
get
Fetch a single subscription by topic and identifier.
| Prop | Type | Default |
|---|---|---|
identifier? | string | - |
topicKey? | string | - |
create
Create a new subscription to a topic. You can pass a list of preferences to filter specific workflows or tags.
| Prop | Type | Default |
|---|---|---|
preferences? | NonEmptyArray<PreferenceFilter> | - |
name? | string | - |
identifier? | string | - |
topicName? | string | - |
topicKey? | string | - |
update
Updates an existing subscription.
| Prop | Type | Default |
|---|---|---|
preferences? | NonEmptyArray<PreferenceFilter> | - |
name? | string | - |
delete
Delete a subscription by topic and subscription ID.
TopicSubscription
A TopicSubscription instance represents a single subscription and provides methods for updating or deleting it, as well as managing its preferences.
| Prop | Type | Default |
|---|---|---|
delete? | () => Result<void> | - |
bulkUpdatePreferences? | { (args: BaseSubscriptionPreferenceArgs[]): Result<SubscriptionPreference[]>; (args: InstanceSubscriptionPreferenceArgs[]): Result<...>; } | - |
updatePreference? | { (args: BaseSubscriptionPreferenceArgs): Result<SubscriptionPreference>; (args: InstanceSubscriptionPreferenceArgs): Result<...>; } | - |
update? | { (args: BaseUpdateSubscriptionArgs): Result<TopicSubscription>; (args: InstanceUpdateSubscriptionArgs): Result<...>; } | - |
preferences? | SubscriptionPreference[] | - |
topicKey? | string | - |
identifier? | string | - |
id? | string | - |
Update a subscription
Update subscription metadata or replace its preferences list. Use this method when updating the subscription as a whole. For granular preference updates, use preference-level methods instead.
Update SubscriptionPreference
Each subscription contains a list of SubscriptionPreference objects that you can update individually.
| Prop | Type | Default |
|---|---|---|
update? | (args: { value: RulesLogic; }) => Result<SubscriptionPreference> | - |
condition? | RulesLogic | - |
enabled? | boolean | - |
workflow? | Workflow | - |
subscriptionId? | string | - |
Delete a subscription (instance method)
Types
Notification
| Prop | Type | Default |
|---|---|---|
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> | - |
revertPrimary? | () => Result<Notification> | - |
completeSecondary? | () => Result<Notification> | - |
completePrimary? | () => Result<Notification> | - |
unsnooze? | () => Result<Notification> | - |
snooze? | (snoozeUntil: string) => Result<Notification> | - |
delete? | () => Result<void> | - |
unarchive? | () => Result<Notification> | - |
archive? | () => Result<Notification> | - |
seen? | () => Result<Notification> | - |
unread? | () => Result<Notification> | - |
read? | () => Result<Notification> | - |
severity? | SeverityLevelEnum | - |
workflow? | Workflow | - |
data? | NotificationData | - |
redirect? | Redirect | undefined | - |
tags? | string[] | undefined | - |
channelType? | ChannelType | - |
secondaryAction? | Action | - |
primaryAction? | Action | - |
avatar? | string | - |
archivedAt? | string | null | - |
firstSeenAt? | string | null | - |
readAt? | string | null | - |
createdAt? | string | - |
deliveredAt? | string[] | - |
snoozedUntil? | string | null | - |
isSnoozed? | boolean | - |
isArchived? | boolean | - |
isSeen? | boolean | - |
isRead? | boolean | - |
to? | Subscriber | - |
body? | string | - |
subject? | string | - |
transactionId? | string | - |
id? | string | - |
Subscriber
| Prop | Type | Default |
|---|---|---|
timezone? | string | - |
data? | Record<string, unknown> | - |
locale? | string | - |
avatar? | string | - |
phone? | string | - |
email? | string | - |
lastName? | string | - |
firstName? | string | - |
subscriberId? | string | - |
id? | string | - |