Skip to main content

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

ParameterTypeRequiredDescription
idstringrequiredThe campaign ID.
typestringrequiredVariant type: A or B (case-insensitive).

Request Body

FieldTypeRequiredDescription
htmlstringrequiredThe 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

StatusMessageCause
400Please provide a campaign ID.id path param is missing.
400Invalid variant type. Must be 'A' or 'B'.type is not A or B.
400Please provide the HTML content for this variant.html is missing or empty.
400Invalid request body.Request body could not be parsed.
400We could not find the campaign you are looking for.Campaign not found.
400We could not find the variant you are looking for.Variant not found.
400The campaign cannot be edited while it is being reviewed.Campaign is in PREPROCESSING or IN_REVIEW status.