Installation
Available on GitHub and npm.Usage
Instantiate the Courier client.CourierClient options
Authentication
Courier authenticates with a JWT that your backend mints with your Courier API key, never in client code. covers the token flow, scope strings, reading auth state, signing out, token refresh, and EU-hosted workspaces.CourierClient takes the user and token at construction. See CourierClient options above. The higher-level packages call Courier.shared.signIn instead:
Inbox APIs
The Courier Inbox APIs read and update inbox messages. Pass an optionalfilter to getMessages() to narrow results by tags, archive state, read status, or a creation time lower bound (from, an ISO 8601 datetime string). getUnreadCounts() takes the same shape. See Unread counts.
Unread counts
There are three ways to show unread badges or totals in a custom UI:- a single global count
- batched counts per filter, for tabs or feeds
- the
unreadCountfield returned withgetMessages()
getUnreadMessageCount()
Returns a Promise<number>: the total unread inbox messages for the authenticated user. If you pass tenantId to CourierClient, the count is scoped to that tenant.
getUnreadCounts(filtersMap)
Fetches unread counts for several named filters in one request. Use it for per-tab or per-feed badges without multiple round trips.
Returns
Promise<Record<string, number>>: the same keys as filtersMap, each mapped to an unread count.
If a filter sets status: 'read', the client returns 0 for that key without calling the server (there are no unread messages in a read-only view).
from with other fields so per-tab badges only count messages after a cutoff. Use the same ISO 8601 string as getMessages().
Unread count from getMessages()
getMessages() responses include both count (total messages matching the list filter) and unreadCount. Unless your filter already sets status, unreadCount reflects the unread subset that matches your tags, archived, from, and tenant constraints.
Real-time updates
The SDK doesn’t push a numeric unread total over the socket. Subscribe to inbox message events, then refetch counts (or reload your message list) when relevant events fire.- Call
courierClient.inbox.socket.connect()so the WebSocket is open. - Register listeners with
addMessageEventListener. It returns a function. Call that function to unsubscribe. - Optionally compare
envelope.eventtoInboxMessageEvent(exported from@trycourier/courier-js).
InboxMessageEvent includes: NewMessage ('message'), Read, Unread, Archive, ArchiveAll, ArchiveRead, Clicked, MarkAllRead, Opened, Unarchive, and Unopened. Listen to whichever events should trigger a refresh.
Preferences APIs
The Courier Preferences APIs read and update a user’s Preferences per topic. See the .Brands APIs
The Courier Brands APIs read custom Brand settings. See the .Lists
The Courier Lists APIs subscribe and unsubscribe users to Lists. See the .Models
Inbox
InboxMessage
InboxAction
CourierGetInboxMessagesQueryFilter
Optional filters for getMessages() and entries in getUnreadCounts(). Fields combine with AND logic.
CourierApiUrls
The type of CourierClient apiUrls, and of the same option on signIn in the React and UI packages. It holds the base URLs the SDK talks to, grouped under courier and inbox.
Build one from a preset rather than by hand. A preset is the only supported way to target a region, and it keeps working when a host changes:
CourierApiUrls is exported, so your editor shows the full field list if you need it. See EU and regional endpoints.
Preferences
CourierUserPreferencesTopic
CourierUserPreferencesStatus
CourierUserPreferencesChannel
Brands
CourierBrand
EU and regional endpoints
Most apps use Courier’s default US hosts. Use this section only if your workspace is on the .CourierClient defaults to getCourierApiUrlsForRegion('us') when you omit apiUrls. To target EU, pass a preset:
getCourierApiUrlsForRegion(), and the requirement to mint JWTs in the same region. For the type, see CourierApiUrls under Models.
See the full list of .