# AB_TESTS

ab-tests endpoints.

**Base URL:** `https://api.trustpager.com/functions/v1/api/v1`

## Endpoints

### POST /ab-tests/:test_id/versions

Add a version to a draft A/B test. It gets the next free label (C, D ...). Running tests cannot gain versions: create a new test instead.

**Scopes:** `ab-tests:write` — [full detail](./ab-tests/post-ab-tests-test-id-versions.md)

### POST /ab-tests

Create an A/B test, with two or more versions (labelled A, B, C), for anything that talks to leads or visitors: an agent, a nurture sequence or one automation email, an email blast, a website or landing page, a form, a lead magnet, a booking page, a quote or proposal template, invoice reminders or review requests. It starts as a draft; start it with update_ab_test status "running". Once running, each person is put into one version at random and keeps it. Results (replies, bookings, sales, new leads, opens, clicks, payments, reviews, signatures, opt-outs) are read from the CRM, so nothing has to report them. Only one test per thing can run at a time.

**Scopes:** `ab-tests:write` — [full detail](./ab-tests/post-ab-tests.md)

### DELETE /ab-tests/:test_id

Delete an A/B test with its versions and its record of which lead got which version. A running test must be paused first.

**Scopes:** `ab-tests:delete` — [full detail](./ab-tests/delete-ab-tests-test-id.md)

### DELETE /ab-tests/:test_id/versions/:version_id

Remove a version from a draft A/B test. If it was the control, another version becomes the control.

**Scopes:** `ab-tests:delete` — [full detail](./ab-tests/delete-ab-tests-test-id-versions-version-id.md)

### GET /ab-tests/:test_id

One A/B test with its settings, its versions (and what each one says) and its current results. A website or page test (unit visitor) also returns website_snippet: the script tag and marked elements to paste on the page, which picks each visitor's version with no login and no flicker.

**Scopes:** `ab-tests:read` — [full detail](./ab-tests/get-ab-tests-test-id.md)

### GET /ab-tests/:test_id/results

Results per version: people, then replies, bookings, sales (and their value), new leads, opens, clicks, payments, reviews, signatures and opt-outs, with the rate of each, the chance each version is the best on the test's goal, a verdict (collecting, too_close or winner) and a one-sentence summary. Something counts when it happens within attribution_days of the person being put into a version. If the test is set to auto and a winner is clear, reading the results promotes it.

**Scopes:** `ab-tests:read` — [full detail](./ab-tests/get-ab-tests-test-id-results.md)

### GET /ab-tests

List the A/B tests in this workspace, newest first. Filter by status (draft, running, paused, completed) or by the agent being tested (subject_type plus subject_id).

**Scopes:** `ab-tests:read` — [full detail](./ab-tests/get-ab-tests.md)

### POST /ab-tests/pick

The version a person should get, for anything about to message, call or show them something. Sticky: the first pick is random (by weight) and recorded, and every later pick for that person returns the same version, so nobody sees both. Give contact_id for a known lead, visitor_id for an anonymous website visitor, or both once a visitor becomes a lead (they keep their version). Give test_id, or subject_type plus subject_id to use whichever test that thing is in (returns version null when it is in none: use the normal wording). When the test is paused, anyone new gets the control version and is not counted; when finished, everyone gets the winner.

**Scopes:** `ab-tests:write` — [full detail](./ab-tests/post-ab-tests-pick.md)

### POST /ab-tests/:test_id/promote

Finish an A/B test with a winner. From then on every lead gets that version, including leads who were in the others. Omit version_id to promote the version the results say is winning (refused while there is no clear winner); pass version_id to choose one yourself.

**Scopes:** `ab-tests:write` — [full detail](./ab-tests/post-ab-tests-test-id-promote.md)

### PATCH /ab-tests/:test_id

Change an A/B test's settings, or start, pause or resume it with status. Starting needs at least two versions, and is refused (409) when the agent already has a running test. Pausing keeps leads in the versions they have and gives new leads the control version. To finish a test use promote_ab_test_winner.

**Scopes:** `ab-tests:write` — [full detail](./ab-tests/patch-ab-tests-test-id.md)

### PATCH /ab-tests/:test_id/versions/:version_id

Edit a version. The name can change at any time; its content, weight and control flag only while the test is a draft, so results always describe what leads actually got.

**Scopes:** `ab-tests:write` — [full detail](./ab-tests/patch-ab-tests-test-id-versions-version-id.md)
