Contacts, broadcasts, templates and automations
The audience features are short summaries here. Every call, field and response is in the API reference. All of them need a full-access key.
Contacts, segments, topics and properties
- A contact is an email address with optional
first_name,last_name,unsubscribedand your ownproperties.POST /contactscreates a contact, or updates the one with that email.PATCH /contacts/:idtakes the id or the email address. - A segment is a named group of contacts. Add and remove membership with
POSTandDELETE /contacts/:id/segments/:segment_id, or list them withGET /segments/:id/contacts. The older/audiencespaths are the same data. - A topic is a kind of mail people can opt in to or out of, with a
default_subscriptionofopt_inoropt_out. Read and change a contact's choices withGETandPATCH /contacts/:id/topics. - A contact property defines a custom field (a
stringor anumber) that contacts can carry inproperties. POST /contacts/importsimports a CSV, up to 5,000 rows a file;GET /contacts/imports/:idreports the result.
Each contact change fires a contact.* webhook. Every list endpoint pages with limit (1 to 100, default 20), after and before.
Templates
A template is HTML with {{{VARIABLE}}} placeholders. {{{VARIABLE|fallback}}} gives a default. Values are escaped in the HTML part. Create one, edit it, then publish it: a send always uses the latest published version, and POST /templates/:id/publish makes a new version. POST /templates/:id/duplicate copies one.
Send with a template by naming it instead of giving html or text:
await resend.emails.send({
from: 'Acme <hello@yourdomain.com>',
to: ['ann@example.com'],
template: { id: 'welcome', variables: { NAME: 'Ann' } },
});
id is the template's id or alias. Your own from, subject and reply_to win over the template's. A variable with no fallback that you leave out answers 422 validation_error; sending html or text together with template does too.
Broadcasts
A broadcast sends one email to every contact of a segment, optionally limited to a topic.
POST /broadcastswithsegment_id,from,subject, andhtmlortext. Add"send": trueto send at once, andscheduled_atwith it to send later.- Or leave it a draft, edit it with
PATCH /broadcasts/:id, thenPOST /broadcasts/:id/send(with an optionalscheduled_at). POST /broadcasts/:id/cancelstops a queued or scheduled one.GET /broadcasts/:id/recipientsandGET /broadcasts/:id/clicked-linksreport on it.
Contacts who unsubscribed or opted out of the topic are skipped, and so are suppressed addresses. Put {{{RESEND_UNSUBSCRIBE_URL}}} in your HTML or text where each contact's unsubscribe link belongs ({{{EMAIL}}}, {{{FIRST_NAME}}} and {{{LAST_NAME}}} work too); every message also carries the List-Unsubscribe headers. A broadcast can only leave from a domain the operator has enabled for broadcasts, so newsletter complaints stay away from your transactional domain. Sending goes out in batches of 20 contacts and respects your caps: when a cap is hit the batch waits.
Automations
An automation is a graph of steps that starts when you send an event. POST /events defines an event name (with an optional typed schema), and POST /events/send records one for a contact, which starts every enabled automation that listens for it.
A graph has exactly one trigger step, up to 50 steps in all, and no loops. Step types are trigger, delay, send_email, wait_for_event, condition, contact_update, contact_delete and add_to_segment, joined by connections (default, condition_met, condition_not_met, event_received, timeout). POST /automations/:id/stop stops new runs (a run under way finishes), GET /automations/:id/runs lists its runs, and POST /automations/:id/runs/:run_id/cancel cancels a run. An email step is sent once per run even if the step is retried.