@brudcast/node is the official Node.js library for the Brudcast API. Anything your
API key can do in the platform API has a method: manage contacts, lists and
segments, import contacts, run campaigns, read delivery logs and reports, set up sending domains,
handle form submissions and manage webhooks. It also sends email through the
email send API and verifies
webhook signatures.
It runs on Node.js 20 or later, Bun and Deno, and has no dependencies.
Install
Create a client
apiKey is your organization API key, used for every call except sending email. sendingKey is a
sending key for one of your sending domains, used by emails.send. When you leave either out, the
library reads BRUDCAST_API_KEY and BRUDCAST_SENDING_KEY from the environment.
What you can do
Each area of the API has its own property on the client. A call needs the scope listed for its area: theread scope to read and the write scope to change anything. See
API keys for the scopes.
Each method returns the record from the reply’s
data.
Contacts, lists and segments
previewCount tells you how many contacts the rules match before you save the segment. See
Segments.
Import contacts from a CSV file
contactImports.retrieve to follow its status. See
Import contacts.
Run a campaign
readiness returns the same checks as the send checklist, so you can
see what’s missing before you send.
Set up a sending domain
sendingDomains.retrieve to see the domain’s status. See
Add a sending domain.
Send email
idempotencyKey that you store with the order. If your process stops after sending, a
retry with the same key returns the first result instead of sending the email again. Brudcast keeps
each key for 24 hours.
Page through lists
Awaiting a list returns its first page. Looping over it withfor await fetches every page in turn:
Handle errors
A failed call throws an error with the HTTPstatus, the API’s code and a requestId. Quote the
requestId when you contact support.
Retries and timeouts
The library retries a failed call twice, waiting longer each time, or as long as the reply’sRetry-After asks. It retries a create only with an idempotency key, which it adds to every POST
for you, so a retry can’t create the same thing twice. Each attempt times out after 60 seconds.
Verify webhooks
Import from@brudcast/node/webhooks and pass the raw request body:
Use
express.raw() on the webhook route, not express.json(). Parsing the body changes its
bytes, so the signature can never match.