Skip to content
BuildBase

Notifications overview

Send email and push notifications to a user or a whole workspace through one gated call.

bb.notification.send() delivers one notification across email and push at once. Channel selection is not your decision at the call site - the org settings, the event config, and the end user's workspace preferences decide which channels actually fire.

import BuildBase from '@buildbase/sdk';

const bb = BuildBase({
  serverUrl: 'https://api.console.buildbase.app',
  orgId: process.env.BUILDBASE_ORG_ID!,
  getSessionId: async () => getCookies().get('bb-session-id')?.value ?? null,
});

const result = await bb.notification.send(
  workspaceId,
  'comment_added',
  userId,
  {
    message: 'Alice commented on your project',
    url: '/projects/42#comment-8',
  }
);

// An event switched off in the console sends nothing and says so.
if (result.reason === 'event_disabled') {
  console.warn('This notification event is turned off.');
} else if (!result.channels?.email && !result.channels?.push) {
  // `sent` only tells you a recipient was resolved - check `channels`
  // to see whether email or push actually went out.
  console.warn('Notification resolved a recipient but sent nothing.');
}

Before you start

Create the notification event in the console under Messaging > Notification events, Create custom event. Its email template is made for you (custom-notification-<slug>); edit it under Messaging > Templates. An event with no template still fires push but reports channels.email: false.

Parameters

ParameterTypeDefaultDescription
workspaceIdstringRequiredWorkspace the notification belongs to
eventstringRequiredEvent slug, e.g. comment_added
userIdstring-User to notify. Omit to notify every workspace member
dataNotificationData{}Merge data for the template and the push payload

Omitting userId is the workspace broadcast. It is an easy mistake to pass null expecting a no-op and mail the entire workspace instead.

Notification data

message does double duty: it is the email body merge value and the push notification body.

FieldTypeDescription
titlestringPush title. Falls back to the event name
messagestringEmail body and push body
iconstringPush icon URL. Falls back to the org icon
imagestringLarge image in the push body
badgestringMonochrome status-bar icon (Android, ChromeOS)
urlstringClick destination. Also {{url}} in the email template
tagstringGrouping key - a new notification with the same tag replaces the previous one instead of stacking
actions{action, title, icon?}[]Action buttons, max 2
silentbooleanDeliver without sound or vibration

Three merge fields are injected for you and overwrite anything you pass under the same key: name and email from the recipient, and workspaceName from the workspace.

Restricting channels for one send

data.channels overrides the event's configured channels for this call only:

// Email only, even if the event also has push enabled
await bb.notification.send(workspaceId, 'invoice_ready', userId, {
  message: 'Your invoice is ready',
  channels: { email: true },
});

The override is opt-in per channel. Once channels is present, a channel missing from the object is treated as false - { email: true } disables push. Omit channels entirely to use the event's configuration.

The override can only narrow, never widen: a channel the gates block stays blocked whether or not you request it.

Scheduling a send

data.scheduledAt (an ISO 8601 date-time) delays the whole notification until that time: the inbox item, the open inbox's refresh, the email and the push all wait, and nothing reaches the person before then.

await bb.notification.send(workspaceId, 'standup', userId, {
  title: 'Standup at 9',
  scheduledAt: '2026-11-10T09:00:00Z',
});
  • The switches are read when it goes out, not when you call: an event, a channel or push switched off in the meantime, a member's changed preferences, or a plan without push all apply then. Someone who has left the workspace by then is not notified.
  • The answer comes back at once, with scheduled: true and scheduledAt. channels says which channels the send is set to use, and notifiedCount how many people it is scheduled for; the gates decide what actually goes out at that time.
  • A time already past is sent now, as a send without scheduledAt is.
  • A value that is not a date ("tomorrow") is refused with 400 and nothing is sent.
  • A time more than 365 days ahead is refused with 400 and nothing is sent.
  • The answer carries scheduledId, which cancels the send (below).
  • Any SDK version. An older self-hosted BuildBase server delivers the inbox item and the email at once and holds back only the push; its answer has no scheduled field, which is how to tell.
{
  sent: true,
  scheduled: true,
  scheduledAt: '2026-11-10T09:00:00.000Z',
  scheduledId: '6730a1f2c4e5b6a7d8e9f012',
  channels: { email: true, push: true },
  notifiedCount: 1,
}

Cancelling a scheduled send

A send that has not gone out yet can be cancelled with its scheduledId, by any member of the workspace who can send to it:

DELETE /api/v1/public/workspaces/:workspaceId/notifications/scheduled/:scheduledId
OutcomeResponse
It was waiting, and now never goes out200 - { cancelled: true, scheduledId }
No scheduled send with that id in this workspace404 - { success: false, message }
It is being delivered, was delivered, failed or was already cancelled409 - { success: false, code: 'SCHEDULED_SEND_NOT_PENDING', status, message }; status says which one
scheduledId is not an id400

Once a send is being delivered it cannot be stopped part way. A cancel and the send's own time arriving together resolve to one or the other, never both.

From the SDK, the cancel is in the next SDK release, after @buildbase/sdk 1.5.0: the server client's bb.notification.cancelScheduled(workspaceId, scheduledId) and, in the browser, WorkspaceApi.cancelScheduledNotification(workspaceId, scheduledId). Each answers { cancelled: true, scheduledId } and throws on a refusal, with the error's code set to SCHEDULED_SEND_NOT_PENDING when the send is no longer waiting. Until that release, send the DELETE above.

const held = await bb.notification.send(workspaceId, 'standup', userId, {
  title: 'Standup at 9',
  scheduledAt: '2026-11-10T09:00:00Z',
});

if (held.scheduledId) {
  try {
    await bb.notification.cancelScheduled(workspaceId, held.scheduledId);
  } catch (err) {
    if ((err as { code?: string }).code === 'SCHEDULED_SEND_NOT_PENDING') {
      // Too late: it is going out, has gone out, or was cancelled already.
    }
  }
}

How long a scheduled send is kept

A scheduled send is kept while it waits, however far ahead it is. Once it finishes (sent, failed or cancelled) its record is removed 30 days later. What each person received stays in their notification history, which is kept for its own, longer period.

What comes back

{
  sent: true,
  channels: { email: true, push: false },
  notifiedCount: 1,
}

channels reports what was actually used, not what was requested. A false means that channel was blocked by the gates, was excluded by a data.channels override, or - for email - that the event has no linked template.

Warning

sent does not mean delivered. It is notifiedCount > 0, and notifiedCount counts the target users the call processed - it increments once per user regardless of whether any channel fired. A call that resolves one user and sends nothing returns sent: true with channels: { email: false, push: false }.

Check channels to know whether anything actually went out.

An event switched off in the console answers { sent: false, reason: 'event_disabled', channels: { email: false, push: false }, notifiedCount: 0 }. Check reason to tell it from a send the gates blocked. An older self-hosted server leaves channels and notifiedCount out of this answer, so read channels with ?. if your app may talk to one.

Errors

ConditionResponse
Workspace does not exist404 - { success: false, message: 'Workspace "…" not found' }
userId does not exist404 - { success: false, message: 'User "…" not found' }
userId is not a member of the workspace404 - { success: false, message: 'User "…" is not a member of this workspace' }
More than 300 sends in an hour from one workspace429 - try again later
data.scheduledAt is not a date-time400 - { success: false, message: 'data.scheduledAt must be an ISO 8601 date-time, ...' }
data.scheduledAt is more than 365 days ahead400 - { success: false, message: 'data.scheduledAt can be at most 365 days ahead' }
A new event slug, with the plan's custom events used up403 - { success: false, code: 'NOTIFICATION_EVENT_NOT_SET_UP', message: 'This notification type is not set up for this app. Ask its owner to add it.' }

A broadcast to a workspace with no members is not an error: it returns sent: false with notifiedCount: 0.

Events you have not set up

Note

Any SDK version; needs a BuildBase server from release 22 . On an older server the send still goes out, unregistered.

You do not have to create an event in the console before sending it. The first send() with a slug the org has never seen registers it, and from then on it is an ordinary custom event: listed in the console, where you can rename it or switch it off, and mutable by each member from their notification settings.

  • It starts with push and the inbox only, which is what an unregistered send always delivered. It has no email template, and the console cannot attach one: set it over the API, PATCH /api/workspaces/notification-events/:id with emailTemplate, and email starts. An event made with Create custom event gets its template, custom-notification-<slug>, when it is made.
  • It counts toward your plan's custom notification events, the same as one created in the console. With none left, a new slug is refused with the 403 above, worded for your end user. Slugs you already have keep sending.
  • The slug is stored lowercase. Letters, digits, ., _, : and - are kept, so comment_added stays comment_added; anything else becomes -.

Emails sent with send() go out as transactional mail, so they do not count toward your plan's monthly emails sent, which meters marketing mail only. Nor does mail BuildBase sends for you, such as sign-in codes and invitations.

The four gates

Every channel passes through canSendNotification() before it fires. The checks run in order and the first failure wins:

  1. Org global switch - the developer turned off all email or all push.
  2. Event master switch - enabled: false on the event kills it outright.
  3. Event channel default - the developer disabled email or push for this specific event.
  4. Preferences - honored only if the event is marked userManaged (in the console, User can toggle this in workspace settings when you create the event, User control when you edit it). Each member's own choice in the workspace wins, then the workspace default. A default a workspace admin marked required is what every member gets.

Layer 4 is the one that surprises people. An event that is not userManaged ignores preferences entirely, which is what you want for security alerts and billing failures. Preferences decide how a member is interrupted, not whether the notification is recorded: with both channels off it still appears in their inbox.

Fail-open behavior

The gate is deliberately permissive:

ConditionResult
No event config exists in the databaseSends - backward compatibility for orgs predating the event registry. A send through the SDK registers it first
The gate throws unexpectedlySends - it never throws upward
Org settings row is missingFalls through to the remaining layers

Notifications fail open so a config gap cannot silently swallow a password reset. The trade-off is that a typo in an event slug registers a new event and delivers it rather than erroring; it shows up in the console's event list. Verify slugs against the 239 events in the event catalog.

Every notification sent this way is also kept in each recipient's inbox, one item per person, whichever channels reached them.

Next Steps