Notifications
Notifications keep you informed about what is happening in your project. Background job completions, mentions from team members, and system events all appear in your notification inbox.
Overview
Every user has a personal notification inbox accessible from the console. Notifications are private — you only see notifications meant for you.
Foir automatically creates notifications for background job results, @mentions in notes, note replies, and system events. You can view, filter, and manage notifications from the inbox or programmatically via the CLI and API.
Notification Types
| Type | Description | Example Trigger |
|---|---|---|
JOB_COMPLETED | A background job finished successfully | Sync completed, search index updated |
JOB_FAILED | A background job failed | Sync error, processing failure |
JOB_PROGRESS | A long-running job has a progress update | Large import/export operations |
MENTION | Someone @mentioned you in a note | Team member tags you for feedback |
NOTE_REPLY | Someone replied to your note | Response to your comment |
NOTE_RESOLVED | A note you are involved in was resolved | Discussion concluded |
SYSTEM | System event notification | Maintenance notices, feature updates |
ANNOUNCEMENT | Platform-wide announcement | Important platform news |
Notification Properties
Each notification includes:
| Field | Description |
|---|---|
title | Short summary (e.g., “Shopify sync completed”) |
message | Optional detail message |
actionUrl | Link to the relevant content or page |
type | Notification category (see types above) |
isRead | Whether you have read this notification |
createdAt | When the notification was created |
In the console
Viewing Notifications
- Click the notification bell icon in the header
- See your recent notifications with unread count
- Click a notification to navigate to the related content
- Mark individual notifications as read or mark all as read
The bell shows your most recent notifications and has no filters. To list only unread ones, use foir notifications list --unread, or the myNotifications query with unreadOnly (and category to narrow to one category).
Managing Notifications
- Mark as read (single) — click a notification or use the mark-as-read action
- Mark all as read: click Mark all read to clear your unread count
Automatic Notifications
Foir creates notifications automatically for:
- Background jobs — When you trigger operations like syncs, search indexing, or file processing, you receive a notification when the job completes or fails. This lets you navigate away and continue working.
- Mentions — When a team member @mentions you in a note, you receive a notification linking directly to the note.
- Note activity — When someone replies to a note you authored or resolves a note you are involved in.
Via the CLI
# List your notifications
foir notifications list
# Mark a notification as read
foir notifications read <id>
# Mark all notifications as read
foir notifications read-allVia the API
Real-time notifications
Subscribe to the notification GraphQL subscription on api.foir.dev/graphql/ws to stream notifications as they happen, without polling.
connectionParams need both credentials: an apiKey (a publishable key is the intended browser credential) and Authorization: Bearer <userAccessToken>. The stream charges notifications:read on the key and is filtered to the bearer’s own user id, so a caller only ever receives their own notifications.
import { createClient } from "graphql-ws";
const client = createClient({
url: "wss://api.foir.dev/graphql/ws",
connectionParams: {
apiKey: "foir_pub_your_publishable_key",
Authorization: `Bearer ${userAccessToken}`,
},
});
client.subscribe(
{ query: `subscription { notification { userId type title } }` },
{ next: ({ data }) => console.log(`New notification: ${data.notification.title}`) }
);@foir/sdk/data reaches the same stream as foir.ns.notifications.onNotification({ onData }), with reconnection handled for you.
See Real-time and Subscriptions for the full subscription reference.
User Push Notifications
The console inbox above is for your team. For user-facing apps (mobile and web), the public API ships a small surface for sending notifications, push delivery, and per-category preferences. These fields run in a user session (or an api-key carrying the matching scope).
Note: On the data client these are
notificationsnamespace operations —foir.ns.notifications.<field>(), named after the GraphQL field. The namespace also carriesmarkNotificationReadandmarkAllNotificationsRead, the self-scoped read-state changes behind the CLI’snotifications readcommands.
Sending a Notification
Send a notification to one of your users with sendNotification. Requires the notifications:write scope. userId and title are required. Once the project has notification categories, category is required too, and takes the project’s own enum: write it unquoted (category: orders) or pass it in a variable. Everything else is optional.
mutation Send {
sendNotification(input: {
userId: "cust_123"
title: "Your order has shipped"
message: "Tracking number 1Z999..."
category: "orders"
actionUrl: "/orders/abc"
imageUrl: "https://cdn.foir.dev/media/box.png"
expiresAt: "2026-07-01T00:00:00Z"
})
}The same send through the data client:
await foir.ns.notifications.sendNotification({
input: {
userId: 'cust_123',
title: 'Your order has shipped',
message: 'Tracking number 1Z999...',
category: 'orders',
actionUrl: '/orders/abc',
imageUrl: 'https://cdn.foir.dev/media/box.png',
expiresAt: '2026-07-01T00:00:00Z',
},
});| Field | Type | Notes |
|---|---|---|
userId | ID! | Recipient user (required) |
title | String! | Short headline (required) |
message | String | Optional detail body |
category | String, or the project’s NotificationCategory! enum once it has categories | Category key, used for per-category preferences |
actionUrl | String | Link to open when the notification is tapped |
imageUrl | String | Thumbnail / rich-push image URL |
metadata | JSON | Arbitrary data carried with the notification |
channels | JSON | Per-channel delivery overrides (see below) |
expiresAt | DateTime | When the notification should stop being delivered |
idempotencyKey | String | Makes the send safe to retry (see below) |
Sending under retries
Code that sends and then records that it sent, such as an operation telling a user something and marking the record told, cannot tell after a failure between the two whether the user heard. Retrying without a key tells them twice.
Send under an idempotencyKey instead. Sent again with the same key by the same caller, the send answers true and delivers nothing a second time. Build the key from what the send is about, so one event is one key:
await foir.ns.notifications.sendNotification({
input: {
userId: request.ownerId,
title: 'Your size is back in stock',
idempotencyKey: `back-in-stock:${request.id}:${request.restockedAt}`,
},
});- The key belongs to the caller that sent it. An operation’s keys are its own, so two apps choosing the same key never answer each other’s sends.
- A key reused for a different send (another user, other words) is refused rather than replayed.
- A send that every channel suppressed writes nothing, so a retry of it is decided afresh against the user’s preferences.
- The key is held for as long as the notification it wrote exists.
Per-channel overrides
The optional channels field is a free-form JSON map keyed by channel name (push, email, …). It is a convention, not a typed-per-channel schema — absent keys fall back to the core fields (title, message, actionUrl, imageUrl). Add a channel by adding its key. By convention:
push—deep_link,thread_id,image,badge, and a free-formdataobjectemail—subject,body,reply_to, andctas(an array of{ label, url })
mutation SendWithChannels {
sendNotification(input: {
userId: "cust_123"
title: "Your order has shipped"
channels: {
push: {
deep_link: "myapp://orders/abc"
thread_id: "orders"
image: "https://cdn.foir.dev/media/box.png"
badge: 1
data: { orderId: "abc" }
}
email: {
subject: "Your order is on its way"
body: "Hi Jane, your order has shipped..."
reply_to: "support@example.com"
ctas: [{ label: "Track order", url: "https://example.com/track/abc" }]
}
}
})
}channels is JSON, so it is passed through the data client unchanged:
await foir.ns.notifications.sendNotification({
input: {
userId: 'cust_123',
title: 'Your order has shipped',
channels: {
push: {
deep_link: 'myapp://orders/abc',
thread_id: 'orders',
image: 'https://cdn.foir.dev/media/box.png',
badge: 1,
data: { orderId: 'abc' },
},
email: {
subject: 'Your order is on its way',
body: 'Hi Jane, your order has shipped...',
reply_to: 'support@example.com',
ctas: [{ label: 'Track order', url: 'https://example.com/track/abc' }],
},
},
},
});Sending in Bulk
Send the same notification to many users at once with sendBulkNotifications. Requires the notifications:write scope. It takes the same fields as sendNotification, except userId is replaced by userIds (a non-empty list of IDs) and it takes no idempotencyKey.
mutation SendBulk {
sendBulkNotifications(input: {
userIds: ["cust_123", "cust_456"]
title: "Weekend sale starts now"
message: "20% off everything until Sunday"
category: "promotions"
actionUrl: "/sale"
})
}The same send through the data client:
await foir.ns.notifications.sendBulkNotifications({
input: {
userIds: ['cust_123', 'cust_456'],
title: 'Weekend sale starts now',
message: '20% off everything until Sunday',
category: 'promotions',
actionUrl: '/sale',
},
});Registering a Device
Register the device’s push token so the platform can deliver push notifications to it. A signed-in user registers and removes their own devices with no permission: the key they come through holds notifications:write, which is what offers the two fields, and nothing is asked of their role or of what the key gives. The device is always the caller’s own. Anybody else is asked for notifications:write: a visitor, a key with nobody signed in, and an operation acting for a user, which declares notifications:write.named. platform is one of IOS, ANDROID, or WEB; deviceName is optional.
mutation Register {
registerDeviceToken(input: {
token: "fcm-or-apns-device-token"
platform: IOS
deviceName: "Jane's iPhone"
})
}
mutation Unregister {
unregisterDeviceToken(token: "fcm-or-apns-device-token")
}Both mutations return a Boolean.
The same pair through the data client:
await foir.ns.notifications.registerDeviceToken({
input: {
token: 'fcm-or-apns-device-token',
platform: 'IOS',
deviceName: "Jane's iPhone",
},
});
await foir.ns.notifications.unregisterDeviceToken({ token: 'fcm-or-apns-device-token' });Notification Preferences
Read the authenticated user’s per-category notification preferences. A signed-in user needs no permission for their own: the key they come through holds notifications:read, and nothing more is asked of their role or of what the key gives.
query Prefs {
notificationPreferences {
category
enabled
channels
}
}Each entry reports a category, whether it is enabled, and the delivery channels for that category. Use the updateNotificationPreference mutation to change one. A signed-in user changes their own with no permission, on the same terms as registering a device: the key holds notifications:write, and the preference changed is always the caller’s own. Sending is a different matter: sendNotification and sendBulkNotifications take notifications:write from the caller’s role or from what the key gives, so a storefront can offer a preferences page without giving its users the send. An operation sets a preference for a user it names with notifications:consent.
The same read through the data client:
const prefs = await foir.ns.notifications.notificationPreferences();updateNotificationPreference is on the same namespace, taking the arguments the GraphQL mutation declares.
Emails that link into your app
Foir’s own emails to a user, such as an invitation or a password reset, link to your app’s pages when the project has an App base URL (in Settings, under General) or their organisation sets one for itself. Without one, those links go to Foir’s hosted pages, so the emails are always sent.
An email you write that links into your app with {base} needs an App base URL to build that link on. Until one is in force for the user, it is refused where it is asked:
- a notification whose email links into your app is refused, and so is its dry run;
- an opt-in to a category that confirms by email is refused when your copy of the confirmation links into your app, because the confirmation could never arrive.
The refusal says why (NO_APP_BASE_URL), and nothing is written or queued. Every other email is sent. An app’s page in the console says so too, when the app emails users.
If an email is lost after it was accepted, for example because the setting was removed in between, the project’s users who can change its settings are told in their inbox, once a day per reason. They can mute that under User email.
A project’s first category
A project with no notification categories takes any category on a send, or none. Once it has one, every send through the API names one of them: the field takes only the project’s list, so a typo is refused when the request is checked and never reaches a user under the wrong preference.
That first category would stop an installed app that sent yesterday. So when a project creates its first category, the category each feature of an installed app sends under is created beside it, called what the app proposes, and the console says which were made. They are released together, so the release that starts the rule gives the apps theirs. The category a feature keeps a user’s consent in is created the same way, as opt-in on every channel. Each is an ordinary category from then on: rename it, change its defaults or retire it.
The same holds for an organization that creates a first category of its own: it reaches the apps installed in that organization and beneath it.
A key that already has a category there, retired or not, is not created again, and neither is a key the project retired when an organization creates its first. Retiring a category is how you say nothing more is sent under it, and an app’s feature that still names it is shown under Needs attention on the app’s page.
A project whose categories are all retired takes any category again, as one with none does. The next category it creates is a first, and brings the apps’ categories in the same way.
Confirming an opt-in by email
A category whose channel is off by default is opt-in: nothing is sent on that channel until the user switches it on. An app can record that opt-in for a user, for example when a shopper fills in a newsletter form.
Each opt-in category says how such an opt-in is applied. Set it on the category in the console, in Settings, under Notifications, with Confirm opt-ins by email:
| Setting | What happens when an app collects an opt-in |
|---|---|
| Off (the default) | The preference switches on at once, recorded with the app that collected it. |
| On | Nothing switches on. The user is sent one email with a link, and the preference switches on when they follow it. A link that is never followed changes nothing, and stops working after 7 days. |
The setting belongs to whoever owns the category. A project sets it for its categories, and an organisation that declares a category under the same key sets it for its own users. Like the rest of a category, a change waits for the next release.
It applies only to switching a channel on, and only to an opt-in an app collected itself:
- Switching off is always immediate.
- A user changing their own preference while signed in, and a user changing one in the console, are applied as they stand.
- A consent an app carries over from the system it was given in (a mirror of another system’s subscriber list) is applied as it stands.
One confirmation email goes to a user for a category in any 24 hours, however often the opt-in is asked for, and none goes to a user who has unsubscribed from every email. The wording of the email is yours to edit and translate with the rest of your project’s email copy, where it is listed as “Opt-in confirmation”.
Web push (browser)
Foir delivers native Web Push (VAPID) to browsers — Chrome, Edge, Firefox, and Safari (including installed iOS 16.4+ PWAs) — with no Firebase in your web frontend. There are two steps: host a service worker, then enrol the browser.
1. Host the service worker
Web Push requires a service worker served from your own origin (it cannot be cross-origin). Save this as foir-sw.js at your site root:
// foir-sw.js -- Foir Web Push service worker.
self.addEventListener('push', (event) => {
event.waitUntil(show(readPush(event.data)));
});
// Foir sends JSON. A push that is not JSON, such as a test sent from the
// browser's developer tools, is shown as its text rather than dropped.
function readPush(data) {
if (!data) return {};
try {
return data.json();
} catch {
return { body: data.text() };
}
}
function show(p) {
// `badge` is a count. The browser shows it on an installed app's icon,
// where it can; a notification's own `badge` option is an image's URL.
const counted =
typeof p.badge === 'number' && 'setAppBadge' in self.navigator
? self.navigator.setAppBadge(p.badge).catch(() => {})
: Promise.resolve();
// A notification replaces the one on screen of its category, and alerts
// again rather than swapping in unseen.
const tag = p.category || undefined;
return Promise.all([
counted,
self.registration.showNotification(p.title || 'Notification', {
body: p.body,
image: p.image,
tag,
renotify: Boolean(tag),
data: { deepLink: p.deepLink, ...(p.data || {}) },
}),
]);
}
self.addEventListener('notificationclick', (event) => {
event.notification.close();
// A deep link may be a path; a window's URL is always whole.
const link = (event.notification.data && event.notification.data.deepLink) || '/';
const url = new URL(link, self.location.origin).href;
event.waitUntil(
clients
.matchAll({ type: 'window', includeUncontrolled: true })
.then((wins) => {
for (const w of wins) {
if (w.url === url && 'focus' in w) return w.focus();
}
return clients.openWindow(url);
}),
);
});The payload keys (title, body, deepLink, image, badge, category, data) are exactly what Foir sends — keep them in sync with the handler above.
A notification of a category replaces the one of that category already on screen, and alerts again. badge is a count, shown on an installed app’s icon in browsers that support it.
A browser that is not running gets the push when it next starts, for up to four weeks, or until the notification’s expiresAt if that is sooner. Nothing is sent after expiresAt.
2. Enrol the browser
Use the @foir/sdk/push helper. It requests notification permission, registers the worker, fetches your project’s VAPID public key, subscribes, and registers the subscription as a WEB device token:
import { enableWebPush, disableWebPush } from '@foir/sdk/push';
import { createFoirClient } from '@foir/sdk/data';
const client = createFoirClient({ apiUrl, apiKey, bearerToken: () => session.getToken() });
// Call from a user gesture (e.g. a "Turn on notifications" button):
const result = await enableWebPush({ client });
if (!result.ok) {
// result.reason: 'unsupported' | 'denied' | 'no-config'
}
// To turn it back off:
await disableWebPush({ client });
// At sign-out, finish push cleanup while the outgoing session still exists:
try {
await disableWebPush({ client });
} finally {
await session.signOut();
}Pass your existing scoped data client, or create one with your hosted session’s getToken() callback as above. The helper stores no bearer or refresh token. Before switching accounts, await disableWebPush using the outgoing account’s client, then end that session. Unregistration runs before local unsubscription; local unsubscription also runs when the network fails. Enrolment for the next account is explicit, using its own data client.
From then on, any user notification you send with push enabled is delivered to the browser. Expired subscriptions are detected on send (a 404/410 from the push service) and their device token is deactivated automatically. A push the push service can’t take at that moment, because it is down or overloaded or the connection fails, is sent to that device again, up to eight times over about two and a half hours. A device it already reached is not sent it twice.
Browser support. Web Push works in Chrome, Edge, and Firefox on desktop and Android. On Apple platforms it needs Safari 16.4+, and on iOS/iPadOS the site must be added to the Home Screen (installed as a PWA) before
enableWebPush()can subscribe.
Best Practices
- Check notifications regularly — they surface important job results and team activity.
- Use action URLs — click notifications to jump directly to the relevant content.
- Mark as read — keep your inbox clean so new notifications stand out.
- Monitor job notifications — failed jobs may need your attention.
- Use SSE or WebSocket channels for real-time integrations instead of polling the API.