Skip to main content
The Courier Node.js SDK provides typed access to the Courier REST API from server-side TypeScript or JavaScript. Use it to send notifications, manage users and profiles, work with templates, and more. Available on GitHub and npm.

Installation

Requires Node.js 20+ (LTS), TypeScript 4.9+. Also works in Deno 1.28+, Bun 1.0+, Cloudflare Workers, and Vercel Edge Runtime.

Quick Start

The client reads COURIER_API_KEY from your environment automatically. You can also pass it explicitly: new Courier({ apiKey: 'your-key' }).

Authentication

Get your API key from Settings > API Keys in the Courier dashboard. Set it as an environment variable:
The SDK picks this up by default. To pass it explicitly:

Sending Notifications

With a template

Design your notification in Design Studio, then reference it by ID:

With inline content

Skip templates and define content directly in code:

To multiple recipients

Send to a list of users in a single call:

Available Resources

The SDK covers the full Courier API. Every method is typed and documented in your editor on hover.

Common Operations

Checking Message Status

After sending, use the requestId to check delivery status or get the full event timeline:
You can also list recent messages with optional filters:

Managing User Profiles

Profiles store recipient data (email, phone, custom fields) that Courier uses for delivery. You need a profile before you can send to a user_id.
create merges with any existing profile. Use replace for a full overwrite (any fields not included will be removed).

Issuing JWT Tokens

If you use Courier’s client-side SDKs (React, JavaScript, mobile), your backend needs to issue JWT tokens for user authentication. The auth.issueToken method handles this:
The scope string controls what the token can access. Common scopes:

Bulk Sending

For large recipient lists, use the bulk API. It works in three steps: create a job, add users, then run it.
For email-based bulk jobs, include profile.email on each user. The to.email field alone is not sufficient for email provider routing.

TypeScript Types

The SDK ships with full TypeScript definitions for every request and response. Import them directly:
All methods, parameters, and response fields have docstrings that appear on hover in VS Code and other editors.

Configuration

Error Handling

The SDK throws typed errors for API failures. All errors extend Courier.APIError:

Retries

The SDK automatically retries failed requests up to 2 times with exponential backoff. Retried errors include connection failures, 408, 409, 429, and 5xx responses.

Timeouts

Requests time out after 60 seconds by default. Configure globally or per-request:
On timeout, an APIConnectionTimeoutError is thrown. Timed-out requests are retried by default.

Logging

Enable debug logging with the COURIER_LOG environment variable or the logLevel client option:
At debug level, all HTTP requests and responses are logged including headers and bodies. You can also pass a custom logger (pino, winston, etc.):

Raw Response Access

Access HTTP headers or the underlying Response object:

Journeys

Journeys are multi-step workflows (send, delay, branch, throttle, digest, and more). Invoke one by ID or alias to start a run, then cancel runs by ID or a shared cancelation token.
cancel takes exactly one of run_id or cancelation_token (spelled with one “l”). You can also build and manage journeys from code with client.journeys.create, list, publish, and archive. See Build journeys via API.

More Operations

The SDK covers the full Courier REST API. Here are a few more resources beyond what’s documented above:

API Reference

Full REST API docs with request/response examples.

Send API

Learn about the Send endpoint, routing, and message options.

Quickstart

Send your first notification in under two minutes.

GitHub

Source code, issues, and changelog.