Create campaign
POST /campaigns — create a draft campaign against a sending domain.
/campaignsCreates a draft campaign. The domain selects the recipients — the campaign sends to that domain’s contact pool — and the from address must be on a verified domain (it does not have to match domain). You must supply html, text, or both. Returns the new campaign id.
domainstringrequiredThe sending domain whose contacts receive the campaign (one of your domains). Orthogonal to from — the from address may be on a different verified domain. Passing audience_id is no longer accepted — pass domain.
fromstringrequiredSender address on a verified domain, e.g. Acme <news@yourdomain.com>.
subjectstringrequiredSubject line. Supports merge tags.
htmlstringoptionalHTML body. Required if text is omitted. Supports merge tags. Markdown-style [text](url) links and bare URLs (https://… / www.…) in the body text are converted to tracked hyperlinks automatically at send time; content already inside <a> tags, attribute values, and <pre>/<code> blocks is left untouched.
textstringoptionalPlain-text body. Required if html is omitted. Supports merge tags.
reply_tostring | string[]optionalOptional Reply-To address. For multiple addresses, send an array of strings.
namestringoptionalThe friendly name of the campaign. Only used for internal reference.
preview_textstringoptionalOptional preview text shown in the inbox after the subject line. Supports merge tags (rendered per recipient). Max 150 characters. Follow-ups do not inherit it.
segment_idstringoptionalNarrow the send to a segment of the domain’s contacts. The segment must belong to the same domain.
topic_idstringoptionalGate the send on topic subscription — only recipients subscribed to this topic receive the campaign.
sendbooleanoptionalWhen true, send (or schedule) the campaign immediately after create, without a separate POST /campaigns/:id/send call.
scheduled_atstringoptionalUsed with send: true. ISO 8601 timestamp or natural-language phrase (e.g. in 1 hour). If in the future the campaign is scheduled rather than sent now.
recurrencestringoptionalMake the campaign repeat on a cadence: daily, weekly, or monthly.
recurrence_everynumberoptionalNumber of periods between recurring sends (1–365). Defaults to 1.
ab_testobjectoptionalA/B test configuration. Set enabled: true and supply at least one variant-B field (subject_b, html_b, text_b). test_pct (1–100, default 20) controls the split; metric (open, click, or reply, default open) picks the winner; eval_hours (1–168) sets how long to run the test before evaluating and sending the winner.
import { MailBlastr } from 'mailblastr';
const mb = new MailBlastr('mb_xxxxxxxxx');
const { data, error } = await mb.campaigns.create({
"domain": "yourdomain.com",
"from": "Acme <news@yourdomain.com>",
"subject": "What's new in June",
"html": "<p>Hi {{FIRST_NAME}}!</p>",
"name": "June newsletter"
});
console.log({ data, error });Response
{
"id": "8f5c2a1e-7b3d-4f9a-9c12-2e6d4a7b8c90"
}missing_required_field if from, subject, or domain is absent; validation_error if neither html nor text is provided, the domain is not yours, or audience_id is passed (no longer accepted — pass domain); invalid_from_address if from is malformed.