---
title: "Adicionar teste A/B"
method: POST
path: "/v1/campaigns/{campaignId}/ab-test"
tags: ["Campanhas"]
---

# Adicionar teste A/B

`POST /v1/campaigns/{campaignId}/ab-test`

## Request

- Base URL: `https://api.ararahq.com`
- URL: `https://api.ararahq.com/v1/campaigns/{campaignId}/ab-test`
- Auth: HTTP bearer
- TypeScript: <https://skmtc.dev/ararahq/apis/ararahq-api/docs/v1/campaigns/:campaignId/ab-test/post.ts> (a function with typed inputs; its response is checked against the schema)

Prefira o campo `abTest` no `POST /v1/campaigns`: lá o teste nasce junto com
a campanha. Criado depois, parte dos contatos pode já ter sido enviada sem o
teste. Nesta rota `variantATemplateName` é obrigatório e o padrão de
`autopilot` é `false`. Permissão: `CAMPAIGNS_SEND`.

## Path parameters

- `campaignId` string, uuid, required

## Request body

- CreateAbTestRequest
  - `variantATemplateName` string, required
  - `variantBTemplateName` string, required
  - `metric` 'DELIVERED' | 'READ' | 'CLICKED' | 'CONVERTED', required
  - `samplePct` integer
  - `splitPct` integer
  - `decisionWindowMinutes` integer
  - `autopilot` boolean: Nesta rota o padrão é `false`.

## Response `201`

Teste criado

- AbTestResponse
  - `id` string, uuid, nullable
  - `campaignId` string, uuid, nullable
  - `variantATemplateName` string, required
  - `variantBTemplateName` string, required
  - `metric` string, required
  - `samplePct` integer, required
  - `splitPct` integer, required
  - `decisionWindowMinutes` integer, required
  - `autopilot` boolean, required
  - `winner` 'A' | 'B', nullable
  - `decidedAt` string, date-time, nullable
  - `decidedReason` string, nullable
  - `pValue` number, nullable
  - `relativeLiftPct` number, nullable
  - `variantAMetricsJson` string, nullable: JSON serializado em string.
  - `variantBMetricsJson` string, nullable
  - `createdAt` string, date-time, nullable

## Other responses

- `400`: `INVALID_AB_TEST` (métrica ou split inválido).
- `401`: Chave inexistente, revogada, expirada, com prefixo errado (`ara_` sem `ara_live_`) ou vinda de IP fora da allowlist. O corpo é o JSON padrão do Spring, sem `error.code`.
- `403`: Dois casos, com corpos diferentes: - Autenticação: header `Authorization` ausente, Bearer que não começa com `ara_`, chave sem a permissão da rota ou rota que não aceita chave de API. Corpo no formato padrão do Spring, sem `error.code`. - Regra de negócio, no formato `{ "error": { ... } }`: `PLAN_FEATURE_LOCKED`, `PLAN_LIMIT_REACHED`, `ACCOUNT_NOT_ACTIVATED`, `NO_DEDICATED_NUMBER`, `ORGANIZATION_SUSPENDED`, `NUMBER_BLOCKED`, `FRAUD_SUSPECTED`, `RESOURCE_FORBIDDEN`, `VIEWER_READ_ONLY`.
- `404`: Campanha não encontrada (sem corpo).
- `429`: `RATE_LIMIT_EXCEEDED`: limite geral da API (1.200 leituras ou 3.000 escritas por minuto, por usuário da chave).

## Changes

- **2026-10-12** `d576cd28afc0`: 3 info
  - api tag `Campanhas` added
  - api tag `campaigns` removed
  - added the non-success response with the status `429`
- **2026-09-15** `372d8c2e735d`: 12 breaking, 1 warning, 8 info
  - removed the enum value `CLICK_RATE` of the request property `metric`
  - removed the enum value `CONVERSION_RATE` of the request property `metric`
  - removed the enum value `DELIVERY_RATE` of the request property `metric`
  - removed the enum value `READ_RATE` of the request property `metric`
  - …17 more
- **2026-05-25** `4e426b85f784`: 1 info
  - endpoint added

[Operation history](https://skmtc.dev/ararahq/apis/ararahq-api/changes/v1/campaigns/:campaignId/ab-test/post.md)

---

[API](https://skmtc.dev/ararahq/apis/ararahq-api.md) - [All operations](https://skmtc.dev/ararahq/apis/ararahq-api/llms.txt) - [OpenAPI document](https://skmtc.dev/ararahq/apis/ararahq-api/revisions/d576cd28afc0?raw)
