PATCH /api/v1/campaigns/{campaignId}
Edits a draft campaign. A campaign is created with a copy of its template's
HTML, then lives on its own: this endpoint edits that copy — the HTML actually
sent — without touching the template. A campaign that has already been sent or is
sending is frozen and returns 400.
Every field is optional; only those you send are changed. tagId, topicId and
sendingIdentityId follow the same rule with an explicit null: leaving the field out keeps what
is there, sending null clears it. That is the only way to detach an editorial topic from a
draft — see Topics.
Mailchimp merge tags in the HTML are converted as on template creation; any
unsupported tag is returned in unsupportedTags.
Authorization
| Role in the organization | This endpoint |
|---|---|
OWNER | Allowed |
ADMIN | Allowed |
MEMBER | Refused — 403 |
Path parameters
| Parameter | Type | Description |
|---|---|---|
campaignId | string | Identifier of the draft to edit |
Request body
| Field | Type | Required | Description |
|---|---|---|---|
content | string | no | The HTML of the email |
subject | string | no | 1 to 200 characters |
previewText | string | null | no | Preview text, up to 200 characters after trimming. null clears it; omitted on PATCH keeps it. Rendered at {{previewText}} or {{preheader}} |
preheader | string | null | no | Compatible alias of previewText. When both are supplied they must match after trimming, otherwise 400 |
name | string | no | 1 to 100 characters |
listId | string | no | Retargets the campaign; must belong to the org |
tagId | string | no | Narrows the target to a tag, or null to clear |
topicId | string | no | Editorial topic the campaign carries, or null to clear |
templateId | string | no | Re-links the source template; must belong to the org |
sendingIdentityId | string | no | Changes the signing address, or null to fall back to the default |
json
{"previewText": "Timely m’a bloqué mes paiements Stripe pendant 5 jours."}null;
conflicting values return 400. An empty string also removes the preview text.
Example
bash
curl -X PATCH -H "x-api-key: $AGENTMAIL_API_KEY" -H "content-type: application/json" \
https://www.agentsmail.io/api/v1/campaigns/$CAMPAIGN_ID \
-d '{ "previewText": "Timely m’a bloqué mes paiements Stripe pendant 5 jours.", "content": "<html><body><div data-skip-in-text=\"true\" style=\"display:none;max-height:0;overflow:hidden;mso-hide:all;\">{{previewText}}</div><p>Hi {{firstName}}</p><a href=\"{{unsubscribeUrl}}\">Unsubscribe</a></body></html>" }'Response
-
400 Bad Request— invalid fields, preview text over 200 characters, or conflicting aliases. -
200 OK— the call succeeded. -
401 Unauthorized— missing or invalid key, or its owner left the organization. -
403 Forbidden— the key's owner is amemberof the organization, not anadmin. -
404 Not Found— no such resource, or it belongs to another organization. The API never confirms that an id exists to a caller who has no right to it. -
429 Too Many Requests— over 120 requests in a minute for this key.
Response fields
| Field | Type | Description |
|---|---|---|
success | boolean | Indicates if the operation was successful |
data.id | string | Unique identifier for the campaign |
data.name | string | Its internal name |
data.subject | string | The subject recipients see |
data.previewText | string | null | Saved preview text; equal to data.preheader |
data.preheader | string | null | The preview text shown after the subject, null when there is none |
data.status | string | draft, scheduled, paused, sending, sent, failed |
data.listId | string | The list it targets |
data.tagId | string | null |
data.topicId | string | null |
data.segmentId | string | null |
data.scheduledAt | string | null |
data.sentAt | string | null |
data.createdAt | string | ISO creation date |
data.updatedAt | string | ISO date of the last change |
Example response
json
{
"success": true,
"data": {
"id": "4d19c0a2",
"name": "Newsletter",
"subject": "August news",
"previewText": "Three new things this month",
"preheader": "Three new things this month",
"status": "subscribed",
"listId": "0b7c51e8",
"tagId": "7c2ef4b1",
"topicId": null,
"segmentId": "3f81aa2c",
"scheduledAt": "2026-08-23T10:22:05.000Z",
"sentAt": "2026-08-23T10:22:05.000Z",
"createdAt": "2026-08-23T10:22:05.000Z",
"updatedAt": "2026-08-23T10:22:05.000Z"
}
}Notes
The HTML must contain{{previewText}} or {{preheader}}, usually in a hidden block.
AgentsMail does not insert a block. See Merge tags.