package main
import (
"context"
"fmt"
"log"
"os"
"github.com/AhaSend/ahasend-go"
"github.com/AhaSend/ahasend-go/api"
"github.com/AhaSend/ahasend-go/models/common"
"github.com/AhaSend/ahasend-go/models/requests"
"github.com/google/uuid"
)
func main() {
client := api.NewAPIClient(api.WithAPIKey(os.Getenv("AHASEND_API_KEY")))
accountID := uuid.MustParse(os.Getenv("AHASEND_ACCOUNT_ID"))
ctx := context.Background()
listID := uuid.MustParse("22222222-2222-4222-8222-222222222222")
templateID := uuid.MustParse("33333333-3333-4333-8333-333333333333")
// The campaign copies the campaign template's design; later changes to
// the template do not reach it. Every field but Name can be set later.
response, _, err := client.CampaignsAPI.CreateCampaign(ctx, accountID, requests.CreateCampaignRequest{
Name: "October newsletter",
Subject: ahasend.String("Our news for October, {{ first_name }}"),
Preheader: ahasend.String("Three things we shipped this month"),
From: &common.SenderAddress{
Email: "news@yourdomain.com",
Name: ahasend.String("Example"),
},
ListIDs: []uuid.UUID{listID},
TemplateID: &templateID,
})
if err != nil {
log.Fatalf("Error creating campaign: %v", err)
}
fmt.Printf("Created campaign %s, ready: %t\n", response.ID, response.Ready != nil && *response.Ready)
}
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
// The SDK sends a fresh Idempotency-Key automatically and reuses it on its own retries.
const campaign = await client.campaigns.create({
name: "October newsletter",
subject: "What is new in October",
preheader: "Three things we shipped this month",
from: { email: "news@example.com", name: "Example" },
list_ids: ["00000000-0000-4000-8000-000000000010"],
template_id: "00000000-0000-4000-8000-000000000013",
});
console.log("Campaign created.", { id: campaign.id, ready: campaign.ready });
curl --request POST \
--url https://api.ahasend.com/v2/accounts/{account_id}/campaigns \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "<string>",
"subject": "<string>",
"preheader": "<string>",
"from": {
"email": "jsmith@example.com",
"name": "<string>"
},
"reply_to": "jsmith@example.com",
"list_ids": [
"3c90c3cc-0d44-4b50-8888-8dd25736052a"
],
"segment_ids": [
"3c90c3cc-0d44-4b50-8888-8dd25736052a"
],
"exclude_list_ids": [
"3c90c3cc-0d44-4b50-8888-8dd25736052a"
],
"exclude_segment_ids": [
"3c90c3cc-0d44-4b50-8888-8dd25736052a"
],
"content": {
"mjml": "<string>",
"html": "<string>",
"text": "<string>",
"text_is_custom": true,
"markup": "<Email version=\"1\">\n <Heading level=\"3\">Welcome</Heading>\n <Paragraph>Thanks for signing up.</Paragraph>\n</Email>\n",
"markup_error": "<unknown>"
},
"template_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
'import requests
url = "https://api.ahasend.com/v2/accounts/{account_id}/campaigns"
payload = {
"name": "<string>",
"subject": "<string>",
"preheader": "<string>",
"from": {
"email": "jsmith@example.com",
"name": "<string>"
},
"reply_to": "jsmith@example.com",
"list_ids": ["3c90c3cc-0d44-4b50-8888-8dd25736052a"],
"segment_ids": ["3c90c3cc-0d44-4b50-8888-8dd25736052a"],
"exclude_list_ids": ["3c90c3cc-0d44-4b50-8888-8dd25736052a"],
"exclude_segment_ids": ["3c90c3cc-0d44-4b50-8888-8dd25736052a"],
"content": {
"mjml": "<string>",
"html": "<string>",
"text": "<string>",
"text_is_custom": True,
"markup": "<Email version=\"1\">
<Heading level=\"3\">Welcome</Heading>
<Paragraph>Thanks for signing up.</Paragraph>
</Email>
",
"markup_error": "<unknown>"
},
"template_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.ahasend.com/v2/accounts/{account_id}/campaigns",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'name' => '<string>',
'subject' => '<string>',
'preheader' => '<string>',
'from' => [
'email' => 'jsmith@example.com',
'name' => '<string>'
],
'reply_to' => 'jsmith@example.com',
'list_ids' => [
'3c90c3cc-0d44-4b50-8888-8dd25736052a'
],
'segment_ids' => [
'3c90c3cc-0d44-4b50-8888-8dd25736052a'
],
'exclude_list_ids' => [
'3c90c3cc-0d44-4b50-8888-8dd25736052a'
],
'exclude_segment_ids' => [
'3c90c3cc-0d44-4b50-8888-8dd25736052a'
],
'content' => [
'mjml' => '<string>',
'html' => '<string>',
'text' => '<string>',
'text_is_custom' => true,
'markup' => '<Email version="1">
<Heading level="3">Welcome</Heading>
<Paragraph>Thanks for signing up.</Paragraph>
</Email>
',
'markup_error' => '<unknown>'
],
'template_id' => '3c90c3cc-0d44-4b50-8888-8dd25736052a'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}HttpResponse<String> response = Unirest.post("https://api.ahasend.com/v2/accounts/{account_id}/campaigns")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"<string>\",\n \"subject\": \"<string>\",\n \"preheader\": \"<string>\",\n \"from\": {\n \"email\": \"jsmith@example.com\",\n \"name\": \"<string>\"\n },\n \"reply_to\": \"jsmith@example.com\",\n \"list_ids\": [\n \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n ],\n \"segment_ids\": [\n \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n ],\n \"exclude_list_ids\": [\n \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n ],\n \"exclude_segment_ids\": [\n \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n ],\n \"content\": {\n \"mjml\": \"<string>\",\n \"html\": \"<string>\",\n \"text\": \"<string>\",\n \"text_is_custom\": true,\n \"markup\": \"<Email version=\\\"1\\\">\\n <Heading level=\\\"3\\\">Welcome</Heading>\\n <Paragraph>Thanks for signing up.</Paragraph>\\n</Email>\\n\",\n \"markup_error\": \"<unknown>\"\n },\n \"template_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.ahasend.com/v2/accounts/{account_id}/campaigns")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"<string>\",\n \"subject\": \"<string>\",\n \"preheader\": \"<string>\",\n \"from\": {\n \"email\": \"jsmith@example.com\",\n \"name\": \"<string>\"\n },\n \"reply_to\": \"jsmith@example.com\",\n \"list_ids\": [\n \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n ],\n \"segment_ids\": [\n \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n ],\n \"exclude_list_ids\": [\n \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n ],\n \"exclude_segment_ids\": [\n \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n ],\n \"content\": {\n \"mjml\": \"<string>\",\n \"html\": \"<string>\",\n \"text\": \"<string>\",\n \"text_is_custom\": true,\n \"markup\": \"<Email version=\\\"1\\\">\\n <Heading level=\\\"3\\\">Welcome</Heading>\\n <Paragraph>Thanks for signing up.</Paragraph>\\n</Email>\\n\",\n \"markup_error\": \"<unknown>\"\n },\n \"template_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n}"
response = http.request(request)
puts response.read_body{
"object": "campaign",
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"name": "<string>",
"subject": "<string>",
"preheader": "<string>",
"from": {
"email": "noreply@example.com",
"name": "Example Corp"
},
"reply_to": "jsmith@example.com",
"status": "draft",
"status_reason": "<string>",
"send_at": "2023-11-07T05:31:56Z",
"send_resumes_at": "2023-11-07T05:31:56Z",
"finished_at": "2023-11-07T05:31:56Z",
"list_ids": [
"3c90c3cc-0d44-4b50-8888-8dd25736052a"
],
"segment_ids": [
"3c90c3cc-0d44-4b50-8888-8dd25736052a"
],
"exclude_list_ids": [
"3c90c3cc-0d44-4b50-8888-8dd25736052a"
],
"exclude_segment_ids": [
"3c90c3cc-0d44-4b50-8888-8dd25736052a"
],
"editor": "advanced",
"content": {
"text_is_custom": true,
"mjml": "<string>",
"html": "<string>",
"text": "<string>",
"markup": "<Email version=\"1\">\n <Heading level=\"3\">Welcome</Heading>\n <Paragraph>Thanks for signing up.</Paragraph>\n</Email>\n",
"markup_error": {
"code": "html_block",
"message": "The design holds an HTML block, which AhaML cannot show; remove the block in the dashboard to read and write the design as AhaML"
}
},
"ready": true,
"issues": [
{
"code": "sender_missing",
"message": "<string>"
}
],
"markup_warnings": [
{
"code": "<string>",
"message": "<string>",
"line": 2,
"column": 2,
"path": "<string>",
"hint": "<string>"
}
]
}Create a Campaign via the API
Create a draft AhaSend marketing campaign with its sender, audience, subject, preview text and design, from MJML, HTML, AhaML or a campaign template.
package main
import (
"context"
"fmt"
"log"
"os"
"github.com/AhaSend/ahasend-go"
"github.com/AhaSend/ahasend-go/api"
"github.com/AhaSend/ahasend-go/models/common"
"github.com/AhaSend/ahasend-go/models/requests"
"github.com/google/uuid"
)
func main() {
client := api.NewAPIClient(api.WithAPIKey(os.Getenv("AHASEND_API_KEY")))
accountID := uuid.MustParse(os.Getenv("AHASEND_ACCOUNT_ID"))
ctx := context.Background()
listID := uuid.MustParse("22222222-2222-4222-8222-222222222222")
templateID := uuid.MustParse("33333333-3333-4333-8333-333333333333")
// The campaign copies the campaign template's design; later changes to
// the template do not reach it. Every field but Name can be set later.
response, _, err := client.CampaignsAPI.CreateCampaign(ctx, accountID, requests.CreateCampaignRequest{
Name: "October newsletter",
Subject: ahasend.String("Our news for October, {{ first_name }}"),
Preheader: ahasend.String("Three things we shipped this month"),
From: &common.SenderAddress{
Email: "news@yourdomain.com",
Name: ahasend.String("Example"),
},
ListIDs: []uuid.UUID{listID},
TemplateID: &templateID,
})
if err != nil {
log.Fatalf("Error creating campaign: %v", err)
}
fmt.Printf("Created campaign %s, ready: %t\n", response.ID, response.Ready != nil && *response.Ready)
}
import { AhaSendClient } from "@ahasend/sdk";
const client = AhaSendClient.fromEnv();
// The SDK sends a fresh Idempotency-Key automatically and reuses it on its own retries.
const campaign = await client.campaigns.create({
name: "October newsletter",
subject: "What is new in October",
preheader: "Three things we shipped this month",
from: { email: "news@example.com", name: "Example" },
list_ids: ["00000000-0000-4000-8000-000000000010"],
template_id: "00000000-0000-4000-8000-000000000013",
});
console.log("Campaign created.", { id: campaign.id, ready: campaign.ready });
curl --request POST \
--url https://api.ahasend.com/v2/accounts/{account_id}/campaigns \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "<string>",
"subject": "<string>",
"preheader": "<string>",
"from": {
"email": "jsmith@example.com",
"name": "<string>"
},
"reply_to": "jsmith@example.com",
"list_ids": [
"3c90c3cc-0d44-4b50-8888-8dd25736052a"
],
"segment_ids": [
"3c90c3cc-0d44-4b50-8888-8dd25736052a"
],
"exclude_list_ids": [
"3c90c3cc-0d44-4b50-8888-8dd25736052a"
],
"exclude_segment_ids": [
"3c90c3cc-0d44-4b50-8888-8dd25736052a"
],
"content": {
"mjml": "<string>",
"html": "<string>",
"text": "<string>",
"text_is_custom": true,
"markup": "<Email version=\"1\">\n <Heading level=\"3\">Welcome</Heading>\n <Paragraph>Thanks for signing up.</Paragraph>\n</Email>\n",
"markup_error": "<unknown>"
},
"template_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
'import requests
url = "https://api.ahasend.com/v2/accounts/{account_id}/campaigns"
payload = {
"name": "<string>",
"subject": "<string>",
"preheader": "<string>",
"from": {
"email": "jsmith@example.com",
"name": "<string>"
},
"reply_to": "jsmith@example.com",
"list_ids": ["3c90c3cc-0d44-4b50-8888-8dd25736052a"],
"segment_ids": ["3c90c3cc-0d44-4b50-8888-8dd25736052a"],
"exclude_list_ids": ["3c90c3cc-0d44-4b50-8888-8dd25736052a"],
"exclude_segment_ids": ["3c90c3cc-0d44-4b50-8888-8dd25736052a"],
"content": {
"mjml": "<string>",
"html": "<string>",
"text": "<string>",
"text_is_custom": True,
"markup": "<Email version=\"1\">
<Heading level=\"3\">Welcome</Heading>
<Paragraph>Thanks for signing up.</Paragraph>
</Email>
",
"markup_error": "<unknown>"
},
"template_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.ahasend.com/v2/accounts/{account_id}/campaigns",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'name' => '<string>',
'subject' => '<string>',
'preheader' => '<string>',
'from' => [
'email' => 'jsmith@example.com',
'name' => '<string>'
],
'reply_to' => 'jsmith@example.com',
'list_ids' => [
'3c90c3cc-0d44-4b50-8888-8dd25736052a'
],
'segment_ids' => [
'3c90c3cc-0d44-4b50-8888-8dd25736052a'
],
'exclude_list_ids' => [
'3c90c3cc-0d44-4b50-8888-8dd25736052a'
],
'exclude_segment_ids' => [
'3c90c3cc-0d44-4b50-8888-8dd25736052a'
],
'content' => [
'mjml' => '<string>',
'html' => '<string>',
'text' => '<string>',
'text_is_custom' => true,
'markup' => '<Email version="1">
<Heading level="3">Welcome</Heading>
<Paragraph>Thanks for signing up.</Paragraph>
</Email>
',
'markup_error' => '<unknown>'
],
'template_id' => '3c90c3cc-0d44-4b50-8888-8dd25736052a'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}HttpResponse<String> response = Unirest.post("https://api.ahasend.com/v2/accounts/{account_id}/campaigns")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"<string>\",\n \"subject\": \"<string>\",\n \"preheader\": \"<string>\",\n \"from\": {\n \"email\": \"jsmith@example.com\",\n \"name\": \"<string>\"\n },\n \"reply_to\": \"jsmith@example.com\",\n \"list_ids\": [\n \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n ],\n \"segment_ids\": [\n \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n ],\n \"exclude_list_ids\": [\n \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n ],\n \"exclude_segment_ids\": [\n \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n ],\n \"content\": {\n \"mjml\": \"<string>\",\n \"html\": \"<string>\",\n \"text\": \"<string>\",\n \"text_is_custom\": true,\n \"markup\": \"<Email version=\\\"1\\\">\\n <Heading level=\\\"3\\\">Welcome</Heading>\\n <Paragraph>Thanks for signing up.</Paragraph>\\n</Email>\\n\",\n \"markup_error\": \"<unknown>\"\n },\n \"template_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.ahasend.com/v2/accounts/{account_id}/campaigns")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"<string>\",\n \"subject\": \"<string>\",\n \"preheader\": \"<string>\",\n \"from\": {\n \"email\": \"jsmith@example.com\",\n \"name\": \"<string>\"\n },\n \"reply_to\": \"jsmith@example.com\",\n \"list_ids\": [\n \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n ],\n \"segment_ids\": [\n \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n ],\n \"exclude_list_ids\": [\n \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n ],\n \"exclude_segment_ids\": [\n \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n ],\n \"content\": {\n \"mjml\": \"<string>\",\n \"html\": \"<string>\",\n \"text\": \"<string>\",\n \"text_is_custom\": true,\n \"markup\": \"<Email version=\\\"1\\\">\\n <Heading level=\\\"3\\\">Welcome</Heading>\\n <Paragraph>Thanks for signing up.</Paragraph>\\n</Email>\\n\",\n \"markup_error\": \"<unknown>\"\n },\n \"template_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n}"
response = http.request(request)
puts response.read_body{
"object": "campaign",
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"name": "<string>",
"subject": "<string>",
"preheader": "<string>",
"from": {
"email": "noreply@example.com",
"name": "Example Corp"
},
"reply_to": "jsmith@example.com",
"status": "draft",
"status_reason": "<string>",
"send_at": "2023-11-07T05:31:56Z",
"send_resumes_at": "2023-11-07T05:31:56Z",
"finished_at": "2023-11-07T05:31:56Z",
"list_ids": [
"3c90c3cc-0d44-4b50-8888-8dd25736052a"
],
"segment_ids": [
"3c90c3cc-0d44-4b50-8888-8dd25736052a"
],
"exclude_list_ids": [
"3c90c3cc-0d44-4b50-8888-8dd25736052a"
],
"exclude_segment_ids": [
"3c90c3cc-0d44-4b50-8888-8dd25736052a"
],
"editor": "advanced",
"content": {
"text_is_custom": true,
"mjml": "<string>",
"html": "<string>",
"text": "<string>",
"markup": "<Email version=\"1\">\n <Heading level=\"3\">Welcome</Heading>\n <Paragraph>Thanks for signing up.</Paragraph>\n</Email>\n",
"markup_error": {
"code": "html_block",
"message": "The design holds an HTML block, which AhaML cannot show; remove the block in the dashboard to read and write the design as AhaML"
}
},
"ready": true,
"issues": [
{
"code": "sender_missing",
"message": "<string>"
}
],
"markup_warnings": [
{
"code": "<string>",
"message": "<string>",
"line": 2,
"column": 2,
"path": "<string>",
"hint": "<string>"
}
]
}campaigns:write.
Only name is required. You can set all other fields in this request, or later with Update Campaign. The response gives ready and issues: while the campaign has issues, it cannot be sent. See Issues.
Design:
The design comes from one source:
content.mjmlcreates anadvanceddesign, andcontent.htmlcreates anhtmldesign.content.markupcreates asimpledesign from AhaML: acontent.htmlbeside it is ignored, and acontent.mjmlbeside it is refused. Withcontentthat has none of them, seteditor. Aneditorthat does not agree with the content is refused.editorwithoutcontentcreates an empty design, which you can complete in the dashboard’s editor.template_idcopies the design of a campaign template. The copy belongs to the campaign: later changes to the campaign template do not change it. A campaign template with no HTML is refused. Atemplate_idthat names no campaign template of your account is refused with400campaign template not found.template_idcannot go witheditororcontent.- Without any of them, the campaign has no design yet.
- MJML must pass strict validation. For a validation error, the message gives the line of each problem.
- AhaML must follow the AhaML rules. A refused write lists the problems in
errors, each with its line and column when it has a place in the AhaML. See AhaML errors. - In MJML and HTML, images and stylesheets must use full
https://URLs, such ashttps://example.com/logo.png. The API refuses relative paths, such asimages/logo.png, andhttp:,//,data:,cid:and other schemes. A URL that starts with a template variable, such as{{ logo_url }}, is allowed. AhaML URLs follow the AhaML URL rules. The API cannot upload files. - The MJML, the HTML, the AhaML and a text written by hand can each be at most 200 KB.
- The HTML must have an unsubscribe link before you can send the campaign. In AhaML, write it as
<Link href="{{ unsubscribe_url }}">…</Link>. See Unsubscribe link.
from.emailmust be on a domain of your account with valid DNS records. A paused domain is accepted here, but Send Campaign and Test Campaign refuse it.reply_tois an address only, without a display name.- In
subjectandpreheader, line breaks become spaces, and spaces at the start and end are removed. An empty subject or preview text counts as none. - The API checks the subject, the preview text, the sender and the reply-to by the same rules as the dashboard, and its error messages use the same words.
list_idsandsegment_idshold the lists and segments of your account to send to.exclude_list_idsandexclude_segment_idshold the lists and segments whose contacts get no message. A list or segment that you give twice counts once. See Audience for the rules.- An audience field that you send must leave the campaign at least one list or segment to send to, so
list_idscan be[]with a segment insegment_ids. A list or segment that does not exist, more than 50 lists or 10 segments, or a list or segment that is both included and excluded is refused with400. - To find the ID of a list or a segment, use List Lists or List Segments, or see where to find the ID in the dashboard.
- When a segment of the audience is being built again, the API answers
409withThe campaign's audience is being updated. Try again in a minute.This refusal is not stored: it releases theIdempotency-Key, so a retry with the same key runs again. Retry it after a minute.
Idempotency-Key header. See Idempotency.
Related guides
- API authentication, Permission scopes, Idempotency.
- Campaigns API overview, Test Campaign, Send Campaign, API errors, API rate limits.
Authorizations
Headers
Optional idempotency key for safe request retries. Must be a unique string for each logical request.
An identical request with a completed stored outcome returns the original status and body. An in-progress
execution returns 409, a changed method/path/body returns 422, and a released 5xx execution may run again.
Keys for non-secret responses expire after 24 hours. API-key create responses include a one-time secret_key,
so successful encrypted replay responses for those operations expire after 5 minutes.
255Body
A new draft campaign. Every field but name can be set later with
Update Campaign. The design comes from at most one source: an
editor, content, both, or a template_id. With none of them the
campaign has no design yet.
The lists to send to, in order. A list named twice counts once.
Each must be a list of this account. A campaign uses at most 50
lists and 10 segments, included and excluded together, and an
audience field that is set must leave it at least one list or
segment to send to, so [] is accepted with segment_ids.
50Lists whose contacts get no message from the campaign. A contact with any membership of one, whatever its status, is left out, also when an included list or segment reaches it. A list cannot be both in list_ids and here. Exclusions need at least one list or segment to send to. Responses return the lists by ID.
50Segments whose members get no message from the campaign, also when an included list or segment reaches them. A segment cannot be both in segment_ids and here. Exclusions need at least one list or segment to send to. Responses return the segments by ID.
10The editor of the design. Without content the campaign gets an empty design of this editor, which the dashboard's editor opens. With content, it is required when the content holds none of markup, mjml and html, and must agree with it otherwise; markup means simple, also beside html. Not accepted with template_id, whose editor the design keeps.
advanced, simple, html Response
Campaign created
A campaign as List Campaigns returns it, without its audience, content and issues.
Where the campaign is in its life. Only a draft can be changed or
deleted.
draft: being prepared.validating: scheduled, and its lists and segments are being checked.waiting_for_review: held for a review before it sends.scheduled: accepted, waiting for its send time.sending: sending now.paused: sending stopped for now;status_reasonsays why.sent: every message was sent.canceled: stopped before it finished;status_reasonsays why.failed: could not be sent;status_reasonsays why.
draft, validating, waiting_for_review, scheduled, sending, paused, sent, canceled, failed 
