Skip to main content
The Node.js SDK is @sendflit/sdk. It has no runtime dependencies, uses the built-in fetch, and works in Node.js 18 and later, in TypeScript and in plain JavaScript.
Looking for another language? See the SDK overview.

Install

Create a client

Read your key from the environment. Never put a live key in source code.
The constructor accepts these options:

Send an email

Call send with an email object. It returns the stored email’s id and status.
Every field you can set on the email: The SDK converts camelCase names to the API’s snake_case names for you.

Send with a template

Attachments

Each attachment is an object with a filename, content and an optional contentType. A string is encoded as UTF-8 and a Buffer or Uint8Array is encoded as-is.
Limits:
  • Up to 10 attachments per message.
  • Up to 10 MB per attachment. Larger files are rejected with 422.

Safe retries with idempotency keys

A network timeout doesn’t tell you whether the server sent the email. Pass an idempotency key so a retry can’t send it twice.
If you send the same key with the same body again, the API returns the original result and does not send a second email. If you reuse a key with a different body, the API rejects the request with 409. That means your code has a bug, so generate a new key for a new email. For the full rules, see Idempotency.

Send a batch

batch sends up to 100 emails in one request. The response has a results array with one entry per email, in the order you sent them, and a count.
The second argument is an optional idempotency key that covers the whole batch. An empty array, or more than 100 emails, throws a TypeError or RangeError before any request is made. See Batch sending.

Manage emails

cancelEmail removes an email that is still scheduled. If the email has already been sent, the API returns an error, which the SDK throws as a SendFlitError with the status and body.

Domains

Add the domain, publish the DNS records it returns, then verify it. You can send only from a verified domain.
For the DNS records and the dashboard steps, see Domains.

Suppressions

Suppressed addresses never receive email from your account. Add an address when a recipient unsubscribes or complains.
suppress takes one object. reason is optional and defaults to "unsubscribe". See Emails for how suppressions interact with sending.

Usage and health

health doesn’t need a valid key. Use it in a readiness probe or a startup check.

Verify webhooks

SendFlit signs every webhook request. The signature is an HMAC-SHA256 of the raw request body, sent in the X-Sendflit-Signature header as sha256=<hex>.
The SDK also exports webhookMiddleware(secret). It checks the signature on req.body, which must be the raw Buffer, returns 401 if the check fails, and otherwise sets req.sendflitEvent to the parsed event and calls next(). Keep the body raw until verification finishes. If you parse it first, the signature won’t match. See Webhooks for the event list.

Errors and retries

Every failed request throws a SendFlitError: A request that times out throws SendFlitTimeoutError, a subclass of SendFlitError.
Requests that fail with 429 or a 5xx status are retried up to maxRetries times. The SDK waits for the Retry-After header when it’s present, and otherwise backs off exponentially. Other 4xx responses are not retried. Network failures are thrown right away with status 0. See Errors, retries and limits.

Method reference

Next steps