> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sequenzy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create A/B Test

> Create a campaign A/B test

Create a draft A/B test for a campaign in `draft` or `rejected` status, or convert a sequence email node into an A/B test step. Provide exactly one of `campaignId` or `automationNodeId`. Variant A (the control) is copied from the current email. A campaign or sequence node can have only one A/B test.

## Request

<ParamField body="campaignId" type="string">
  Campaign to attach the test to. Must be in `draft` or `rejected` status.
  Mutually exclusive with `automationNodeId`.
</ParamField>

<ParamField body="automationNodeId" type="string">
  Sequence `action_email` node to convert into an `action_ab_test` step.
  Mutually exclusive with `campaignId`. Requires at least one `variants` entry.
</ParamField>

<ParamField body="confirmLiveChange" type="boolean">
  Required as `true` when `automationNodeId` belongs to an active sequence. This
  acknowledges that the live sequence graph will change immediately.
</ParamField>

<ParamField body="name" type="string">
  Test name. Defaults to `A/B Test for <campaign name>`.
</ParamField>

<ParamField body="testPercentage" type="number">
  Campaign-only share of the audience that receives test sends. Must be from 5
  to 50. Defaults to 20. Sequence tests use `winnerThreshold` instead.
</ParamField>

<ParamField body="testDurationMinutes" type="number">
  Campaign-only duration before a winner is selected. Must be from 15 to 1440
  minutes. Defaults to 240.
</ParamField>

<ParamField body="winnerCriteria" type="string">
  Metric used to pick the winner: `open_rate` or `click_rate`. Campaigns default
  to `open_rate`. For sequence tests, an explicit value overrides the `testType`
  default.
</ParamField>

<ParamField body="testType" type="string">
  Sequence variant strategy: `subject` or `content`. Subject defaults to
  `open_rate` and content defaults to `click_rate` unless `winnerCriteria` is
  explicit. Defaults to `content`. Sequence tests only.
</ParamField>

<ParamField body="winnerThreshold" type="number">
  Number of sequence recipients in the test sample, from 10 to 1000. Defaults to
  100\. Sequence tests only.
</ParamField>

<ParamField body="variants" type="array">
  Extra variants beyond the control. Each item takes `subject` (required),
  `previewText`, and `blocks`. Total variants cannot exceed 5. Variants without
  `blocks` reuse the current email body. Optional for campaign tests; sequence
  conversions require at least one entry.
</ParamField>

```bash theme={null}
curl -X POST "https://api.sequenzy.com/api/v1/ab-tests" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "campaignId": "camp_abc123",
    "testPercentage": 20,
    "winnerCriteria": "open_rate",
    "variants": [{ "subject": "Alternative subject line" }]
  }'
```

For a sequence test, copy the effective values from the source test's
`settings` object:

```bash theme={null}
curl -X POST "https://api.sequenzy.com/api/v1/ab-tests" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "automationNodeId": "node_abc123",
    "testType": "content",
    "winnerCriteria": "open_rate",
    "winnerThreshold": 150,
    "variants": [{ "subject": "Alternative subject line" }]
  }'
```

## Responses

<ResponseExample>
  ```json 200 theme={null}
  {
    "success": true,
    "abTest": {
      "id": "ab_abc123",
      "kind": "campaign",
      "campaignId": "camp_abc123",
      "name": "A/B Test for April Launch",
      "status": "draft",
      "testPercentage": 20,
      "testDurationMinutes": 240,
      "winnerCriteria": "open_rate",
      "settings": {
        "testPercentage": 20,
        "testDurationMinutes": 240,
        "winnerCriteria": "open_rate"
      },
      "variants": [
        { "id": "var_a", "label": "A", "subject": "A quick update" },
        { "id": "var_b", "label": "B", "subject": "Alternative subject line" }
      ]
    }
  }
  ```

  ```json 400 theme={null}
  {
    "success": false,
    "error": "testPercentage must be between 5 and 50"
  }
  ```

  ```json 400 theme={null}
  {
    "success": false,
    "error": "Campaign structure can only be changed in draft or rejected status."
  }
  ```

  ```json 400 theme={null}
  {
    "success": false,
    "error": "Maximum of 5 variants allowed"
  }
  ```

  ```json 401 theme={null}
  {
    "success": false,
    "error": "Unauthorized"
  }
  ```

  ```json 404 theme={null}
  {
    "success": false,
    "error": "Campaign not found"
  }
  ```

  ```json 409 theme={null}
  {
    "success": false,
    "error": "A/B test already exists for this campaign"
  }
  ```

  ```json 500 theme={null}
  {
    "success": false,
    "error": "Failed to create A/B test"
  }
  ```
</ResponseExample>
