Send your first newsletter by API
Create a template, a segment and a campaign, run the pre-flight, start it and read the report, with the credit cost of every step.
This guide takes a workspace from nothing to a delivered newsletter using only the API. Every call is
https://api.messagepipe.dev/v1/... with a workspace API key. Each step says what it costs. Only
three calls spend credits: the test send, the start and a resume after a pause.
The examples use placeholder ids and a placeholder key. Responses are abbreviated to the fields the next step needs.
Before you start
- A brand with a verified sender domain, and a topic on it that your recipients are
subscribed to. Both are set up once in the dashboard (or by API with
audience:admin); you only read them here. - A project id (the template belongs to one).
- Contacts who have subscribed to that topic. Contacts without valid consent are never mailed, however you target them.
- An API key created in the dashboard with exactly the scopes below.
campaigns:sendspends credits, so give it only to the key that runs sends.
| Scope | Used for |
|---|---|
audience:read | Read the brand and topic ids |
content:write | Create and publish the template |
segments:write, segments:read | Create the segment and count it |
campaigns:write | Create the campaign |
campaigns:read | Pre-flight and report |
campaigns:send | Test send and start |
credits:read | Check the balance |
export MP_KEY="mp_live_xxxxxxxxxxxxxxxx" # placeholder: use your own key
export API="https://api.messagepipe.dev/v1"1. Check your balance. 0 credits
curl "$API/credits" -H "Authorization: Bearer $MP_KEY"Look at the email bucket (or email_managed if the brand sends through managed email). A newsletter
costs one credit per recipient message, so you need at least as many as the audience.
2. Find the brand and topic. 0 credits
curl "$API/brands" -H "Authorization: Bearer $MP_KEY"
curl "$API/topics" -H "Authorization: Bearer $MP_KEY"Note the brand's id (brd_...) and the topic's id (top_...).
3. Create the template. 0 credits
Content can be markdown, html or mjml.
curl -X POST "$API/campaign-templates" \
-H "Authorization: Bearer $MP_KEY" -H "Content-Type: application/json" \
-d '{
"project_id": "prj_xxxxxxxx",
"name": "November newsletter",
"brand_id": "brd_xxxxxxxx",
"content": {
"mode": "markdown",
"subject": "What shipped in November",
"preheader": "Three things worth your time",
"source": "Hi there,\n\nHere is what we shipped this month.\n\n- A faster dashboard\n- Scheduled sends\n- Webhooks for campaigns\n"
}
}'The response carries the template id (tpl_...). Check what it will look like, still for free:
curl -X POST "$API/content/preflight" \
-H "Authorization: Bearer $MP_KEY" -H "Content-Type: application/json" \
-d '{ "template_id": "tpl_xxxxxxxx", "brand_id": "brd_xxxxxxxx", "topic_id": "top_xxxxxxxx" }'The findings are the same content checks the dashboard's
editor shows. Then publish the template: a campaign can only be started with published content
(content_not_published otherwise).
curl -X POST "$API/campaign-templates/tpl_xxxxxxxx/publish" \
-H "Authorization: Bearer $MP_KEY" -H "Content-Type: application/json" -d '{}'4. Create the segment and count it. 0 credits
curl -X POST "$API/segments" \
-H "Authorization: Bearer $MP_KEY" -H "Content-Type: application/json" \
-d '{
"name": "Newsletter subscribers",
"type": "dynamic",
"rules": { "all": [ { "topic": { "id": "top_xxxxxxxx", "state": "subscribed" } } ] }
}'
curl "$API/segments/seg_xxxxxxxx/count" -H "Authorization: Bearer $MP_KEY"The count is your expected audience, and so your expected credit cost (a suppressed contact costs
nothing). It needs segments:read, which segments:write does not imply: tick both if one key does
both.
5. Create the campaign. 0 credits
curl -X POST "$API/campaigns" \
-H "Authorization: Bearer $MP_KEY" -H "Content-Type: application/json" \
-d '{
"name": "November newsletter",
"kind": "newsletter",
"brand_id": "brd_xxxxxxxx",
"topic_id": "top_xxxxxxxx",
"segment_id": "seg_xxxxxxxx",
"template_id": "tpl_xxxxxxxx",
"from_name": "Acme",
"from_email": "news@acme.example"
}'The campaign is a draft with an id (cmp_...). Nothing has been sent.
6. Send yourself a test. 1 credit per recipient
A test send costs one credit per test recipient and is the one step you may skip. Starting a campaign
that has never been tested gives a no_recent_test warning, not an error. It needs campaigns:send
and an Idempotency-Key, so a retry cannot send twice:
curl -X POST "$API/campaigns/cmp_xxxxxxxx/test-send" \
-H "Authorization: Bearer $MP_KEY" -H "Content-Type: application/json" \
-H "Idempotency-Key: nov-newsletter-test-1" \
-d '{ "recipients": ["you@acme.example"] }'7. Pre-flight. 0 credits
curl "$API/campaigns/cmp_xxxxxxxx/preflight" -H "Authorization: Bearer $MP_KEY"{ "ok": true, "audience": 4210, "problems": [ { "code": "no_recent_test", "severity": "warning" } ], "findings": [] }ok: true means no error-level problem. An error (an unverified sender domain, no content, no credits,
a blocked link) must be fixed first; start runs this same check again and refuses on any error.
The audience is the number of recipients the start will reserve against your key's daily cap
(10,000 recipients per UTC day by default).
8. Start. 1 credit per recipient message
curl -X POST "$API/campaigns/cmp_xxxxxxxx/start" \
-H "Authorization: Bearer $MP_KEY" -H "Content-Type: application/json" \
-H "Idempotency-Key: nov-newsletter-start-1" \
-d '{}'To schedule instead, pass "scheduled_at": "2026-12-01T09:00:00Z" (more than a minute away); the
campaign is checked again when it fires.
The response is { id, status, scheduled_at, preflight }: the pre-flight the start passed, including a
credits_short warning if you do not have enough credits for everyone. Credits are spent as the
campaign sends, one per message just before it is queued, and are given back if a message cannot be
queued. Starting again with the same Idempotency-Key returns this response and does not start a
second run.
What can refuse the start: 400 validation_failed with details.problems (pre-flight, or
no_credits when the balance is zero), 422 daily_recipient_cap (your key's daily limit, with
remaining and resets_at), 429 (more than 10 starts a minute, with Retry-After).
9. Watch it and read the report. 0 credits
curl "$API/campaigns/cmp_xxxxxxxx" -H "Authorization: Bearer $MP_KEY"
curl "$API/campaigns/cmp_xxxxxxxx/report" -H "Authorization: Bearer $MP_KEY"run.status is running, paused or completed. If credits ran out part-way, the run is paused
with run.pause_reason: "credits_exhausted" and run.recipients.pending says how many are still to
go. Add credits and resume (this spends credits again, for the messages not yet sent):
curl -X POST "$API/campaigns/cmp_xxxxxxxx/resume" \
-H "Authorization: Bearer $MP_KEY" -H "Content-Type: application/json" \
-H "Idempotency-Key: nov-newsletter-resume-1" -d '{}'To stop for any other reason, POST .../pause and later .../resume, or POST .../cancel (neither
pause nor cancel spends credits; messages already sent stay sent).
The report gives sends by status, delivered, bounced, complaint and unsubscribe counts, and
engagement. Opens and clicks are shown by classification (human, mpp, bot, unclassified);
read the human numbers. Opens and clicks are tracked only if the brand has tracking on.
Finally, check what it cost:
curl "$API/credits" -H "Authorization: Bearer $MP_KEY"Don't poll: use webhooks
Instead of polling the campaign, subscribe a workspace-wide webhook endpoint (created in the dashboard
under Webhooks) to campaign.completed, campaign.paused and credits.low. See
Webhooks.
Cost summary
| Step | Credits |
|---|---|
| 1 to 5 (balance, brand and topic, template, segment, campaign) | 0 |
| 6 Test send | 1 per test recipient |
| 7 Pre-flight | 0 |
| 8 Start | 1 per recipient message sent |
| 9 Report, pause, cancel | 0 |
| Resume after a pause | 1 per message still to send |