Make a POST
call to the emails/activities/{campaign_activity_id}/abtest
endpoint to create an A/B test for a primary email campaign activity. This method changes the campaign activity type
from NEWSLETTER
to AB_TEST
and the type_code
from 10
to 57
Request Body
You must include the following properties in the request body:
-
alternative_subject
: The alternate email subject line to use for A/B testing. Currently, A/B tests support subject line only. -
test_size
: The percentage of contact recipients in the A/B Test. For example, if the value is 30, then 30% of contacts will receive the email campaign with subject line A, and 30% of contacts will receive the email campaign with subject line B. Valid values include5
to50
percent, inclusively. -
winner_wait_duration
: The number of hours Constant Contact waits after the A/B test is sent before determining the winning subject line. The winner is the subject line with the highest number of contact opens. After determining the winner, Constant Contact automatically sends the email campaign with the winning subject line to all the remaining contacts that did not participate in the A/B test.
Response Body
The following example shows the A/B test details returned in the response body:
{
"alternative_subject": "{the alternate subject line to use}",
"test_size": 10,
"winner_wait_duration": 6
}
type
back to NEWSLETTER
and the type_code
from 57
to 10
, make a DELETE
call to emails/activities/{campaign_activity_id}/abtest
.
Authorization Requirements
User privileges: campaign:write
Authorization scopes: campaign_data
Parameters
To create an A/B test for an email campaign, specify the email campaign_activity_id
as a URL parameter.
Example Get Email Campaign Activity A/B Test
POST https://api.cc.email/v3/emails/activities/{campaign_activity_id}/abtest
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.cc.email/v3/emails/activities/0c53584f-113e-4b4c-b137-2d3a9e623818/abtest',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>' {
"test_size": 20,
"alternative_subject": "Reminder: Big Sale Coming Soon!",
"winner_wait_duration": 48
}',
CURLOPT_HTTPHEADER => array(
'Accept: application/json',
'Content-Type: application/json',
'Authorization: Bearer {access_token}'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, " {\n \"test_size\": 20,\n \"alternative_subject\": \"Reminder: Big Sale Coming Soon!\",\n \"winner_wait_duration\": 48\n}");
Request request = new Request.Builder()
.url("https://api.cc.email/v3/emails/activities/0c53584f-113e-4b4c-b137-2d3a9e623818/abtest")
.method("POST", body)
.addHeader("Accept", "application/json")
.addHeader("Content-Type", "application/json")
.addHeader("Authorization", "Bearer {access_token}")
.build();
Response response = client.newCall(request).execute();
curl --location --request POST 'https://api.cc.email/v3/emails/activities/0c53584f-113e-4b4c-b137-2d3a9e623818/abtest' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {access_token}' \
--data-raw ' {
"test_size": 20,
"alternative_subject": "Reminder: Big Sale Coming Soon!",
"winner_wait_duration": 48
}'
Response
{
"alternative_subject": "Reminder: Big Sale Coming Soon!",
"test_size": 20,
"winner_wait_duration": 48
}
Schedule the A/B Test
To schedule a draft email campaign A/B test, make a POST call to /emails/activities/{campaign_activity_id}/schedules
. This method requires campaign send user privileges.