Campaigns

A campaign is one email, one audience, one departure. Everything before the send is reversible; the send itself never is.

What a campaign is, over HTTP

A campaign is a template, a subject and a target: one list, optionally narrowed to one tag. It also picks who signs it — one of the addresses in your sender address book, or, by default, the organization's default address.

Scheduling: its own endpoint

Sending now and sending later are two different calls, so one can never be mistaken for the other.
CallWhat it does
POST /api/v1/campaigns/{campaignId}/sendSends now
POST /api/v1/campaigns/{campaignId}/scheduleBooks a draft for an instant, or moves a scheduled one
DELETE /api/v1/campaigns/{campaignId}/scheduleCancels the booking: the campaign is back to draft
bash
curl -X POST -H "x-api-key: $AGENTMAIL_API_KEY" -H "content-type: application/json" \
  -d '{"scheduledAt": "2026-08-12T07:00:00Z"}' \
  "https://www.agentsmail.io/api/v1/campaigns/$CAMPAIGN_ID/schedule"
scheduledAt is an ISO 8601 instant with an explicit offset — a date with no timezone is refused, never read as UTC — and the schedule is kept to the minute. See Schedule a campaign and Unschedule a campaign. A scheduledAt sent to /send is still accepted for older callers, but it is no longer the documented way.
The content is rendered before anything is emitted. It is the exact same check as POST /api/v1/render: a campaign whose HTML carries no {{unsubscribeUrl}} answers 400 and no send is created. Without it, every single send would fail later for a reason the API never shows you. Fix the template, recreate the campaign, then send.
Calling send twice never sends twice. A campaign that already went out answers 409 and no second send is started — retrying after a timeout is safe. If you want to send the same content again, create a new campaign.
Then poll GET /api/v1/campaigns/{campaignId}: status moves draft → sending → sent, and progress fills up along the way. There is no webhook to wait for.

When polling never converges

A 202 means the request was accepted, not that the send will happen. Two conditions stop it after the fact, and neither changes the campaign: it stays draft, progress stays at zero, and no error is ever reported to you.
What you seeWhat it meansWhat to do
draft, progress.total = 0, sendingEnabled = falseMass sending is switched off account-wide (kill switch)Nothing on your side — sending has to be re-enabled
draft, progress.total = 0, sendingEnabled = trueThe 24 h sending quota would be exceeded by this campaign's recipientCountWait for the quota window to roll, then call /send again
Stop polling if the campaign is still draft with no progress. It will never move to sent on its own. Read sendingEnabled: false means the kill switch, true means the daily quota — in both cases the campaign is intact and calling /send again later is safe, it is still a draft.

A campaign from nothing, end to end

1

Write the template

bash
TEMPLATE_ID=$(curl -s -X POST -H "x-api-key: $AGENTMAIL_API_KEY" -H "content-type: application/json" \
  -d '{
    "name": "August newsletter",
    "defaultSubject": "What shipped in August",
    "content": "<html><body><p>Hi {{firstName}}</p><p>Here is what we shipped.</p><a href=\"{{unsubscribeUrl}}\">Unsubscribe</a></body></html>"
  }' \
  "https://www.agentsmail.io/api/v1/templates" | jq -r '.data.id')
Check unsupportedTags in the response: anything listed there is still raw in your HTML.
2

Render it, and read what you get

bash
curl -s -X POST -H "x-api-key: $AGENTMAIL_API_KEY" -H "content-type: application/json" \
  -d '{"templateId":"'$TEMPLATE_ID'","variables":{"firstName":"Camille"}}' \
  "https://www.agentsmail.io/api/v1/render" | jq '{subject, unknownVariables: .data.unknownVariables}'
A 400 here means the HTML has no unsubscribe link. Fix the template with PATCH and render again — this loop costs nothing.
3

Pick the target

bash
LIST_ID=$(curl -s -H "x-api-key: $AGENTMAIL_API_KEY" \
  "https://www.agentsmail.io/api/v1/lists" | jq -r '.data[0].id')

curl -s -H "x-api-key: $AGENTMAIL_API_KEY" \
  "https://www.agentsmail.io/api/v1/tags" | jq '.data[] | {id, name, contactCount}'
List ids come from GET /api/v1/lists — see Discovery. Tags come from the Audience API; keep the id of the one you want, if any.
4

Create the campaign

bash
CAMPAIGN_ID=$(curl -s -X POST -H "x-api-key: $AGENTMAIL_API_KEY" -H "content-type: application/json" \
  -d '{
    "name": "August newsletter",
    "subject": "What shipped in August",
    "templateId": "'$TEMPLATE_ID'",
    "listId": "'$LIST_ID'"
  }' \
  "https://www.agentsmail.io/api/v1/campaigns" | jq -r '.data.id')
5

Count the recipients before committing

bash
curl -s -H "x-api-key: $AGENTMAIL_API_KEY" \
  "https://www.agentsmail.io/api/v1/campaigns/$CAMPAIGN_ID" | jq '.data.recipientCount'
Zero means the target matches nobody. Sending would be a no-op — fix the target first.
6

Send

bash
curl -s -X POST -H "x-api-key: $AGENTMAIL_API_KEY" \
  "https://www.agentsmail.io/api/v1/campaigns/$CAMPAIGN_ID/send"
202 means the send was accepted, not finished.
7

Follow it

bash
curl -s -H "x-api-key: $AGENTMAIL_API_KEY" \
  "https://www.agentsmail.io/api/v1/campaigns/$CAMPAIGN_ID" | jq '{status: .data.status, progress: .data.progress}'
Poll until status is sent. Do not call /send again while waiting — it answers 409. If the campaign is still draft with progress.total at zero, stop polling and read When polling never converges above: sending is switched off, or the daily quota is full.