Set Campaign Variant HTML
Set a variant's HTML directly. This converts the variant to CODE type, stores the cleaned HTML in body_html, and clears body_json.
Only use this endpoint if you want to set HTML directly. Otherwise, prefer Edit Campaign Variant to open the editor session.
Endpoint
POST https://api.campaignlark.com/v1/campaigns/:id/variants/:type/html
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
id | string | required | The campaign ID. |
type | string | required | Variant type: A or B (case-insensitive). |
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
html | string | required | The raw HTML for the variant. Must not be empty. |
Sample Request
POST https://api.campaignlark.com/v1/campaigns/64f1a2b3c4d5e6f7a8b9c0d1/variants/A/html
Content-Type: application/json
{
"html": "<html><body><h1>Hello {{contact.first_name}}</h1></body></html>"
}
Response
Success — 200 OK
Returns the stored content in the same shape as Get Campaign Variant HTML.
{
"error": null,
"data": {
"id": "6512a...",
"type": "A",
"template_type": "CODE",
"body_json": null,
"body_html": "<html><body><span style=\"display:none;max-height:0;overflow:hidden;opacity:0;\">{{preview_text}}</span><h1>Hello {{contact.first_name}}</h1></body></html>"
}
}
Cleaning and Behavior
Before saving, the submitted HTML is cleaned synchronously:
<script>tags are stripped for security.- A hidden preview-text
<span>is injected into<body>so inbox previews render the variant's preview text. - External images are left as-is and are not re-hosted onto the CDN.
The response body_html reflects the cleaned output. The variant is switched to template_type: "CODE", and its preview thumbnail is regenerated asynchronously. A later call to Edit Campaign Variant opens the HTML code editor for this variant.
Errors
| Status | Message | Cause |
|---|---|---|
400 | Please provide a campaign ID. | id path param is missing. |
400 | Invalid variant type. Must be 'A' or 'B'. | type is not A or B. |
400 | Please provide the HTML content for this variant. | html is missing or empty. |
400 | Invalid request body. | Request body could not be parsed. |
400 | We could not find the campaign you are looking for. | Campaign not found. |
400 | We could not find the variant you are looking for. | Variant not found. |
400 | The campaign cannot be edited while it is being reviewed. | Campaign is in PREPROCESSING or IN_REVIEW status. |