---
title: "Create an A/B test"
method: POST
path: "/api/v1/ab-tests"
tags: ["A/B Testing"]
---

# Create an A/B test

`POST /api/v1/ab-tests`

## Request

- Base URL: `https://api.misar.io/mail`
- URL: `https://api.misar.io/mail/api/v1/ab-tests`
- Auth: HTTP bearer

Create a new A/B test variant for a campaign. The campaign must be in draft or ready status.

## Request body

- object
  - `campaign_id` string, uuid, required
  - `variant` string, required: Variant identifier e.g. 'A', 'B'
  - `test_type` 'content' | 'subject' | 'send_time' | 'from_name' | 'preheader', required
  - `subject` string
  - `preheader` string
  - `body_html` string
  - `from_name` string
  - `send_percent` integer, required: % of list to send this variant to
  - `send_time_a` string, date-time
  - `send_time_b` string, date-time
  - `auto_select_winner` boolean
  - `winner_wait_hours` integer

## Response `201`

A/B test created

- object
  - `success` boolean
  - `data` AbTest
    - `id` string, uuid
    - `campaign_id` string, uuid
    - `variant` string
    - `test_type` 'content' | 'subject' | 'send_time' | 'from_name' | 'preheader'
    - `subject` string, nullable
    - `preheader` string, nullable
    - `body_html` string, nullable
    - `from_name` string, nullable
    - `send_percent` integer
    - `emails_sent` integer
    - `opens` integer
    - `clicks` integer
    - `auto_select_winner` boolean
    - `winner_wait_hours` integer
    - `winner_selected_at` string, date-time, nullable
    - `created_at` string, date-time

## Other responses

- `400`: Validation error
- `401`: Invalid API key
- `403`: Insufficient scope — requires send or send:marketing
- `409`: Variant already exists, or campaign already sent
- `415`: Content-Type must be application/json

---

[API](https://skmtc.dev/misar/apis/misarmail-api.md) · [All operations](https://skmtc.dev/misar/apis/misarmail-api/llms.txt) · [OpenAPI document](https://skmtc.dev/misar/apis/misarmail-api/revisions/1141238bc092?raw)
