This document describes the REST API endpoints for managing A/B testing experiments.
http://localhost:3002/api
Currently, no authentication is required for API endpoints.
Check if the API server is running and get basic status information.
GET /health
Response:
{
"status": "OK",
"timestamp": "2025-09-05T19:01:42.316Z",
"experimentsCount": 2
}Retrieve all experiments.
GET /experiments
Response:
[
{
"id": "1",
"name": "Homepage CTA Button Test",
"description": "Testing blue vs red CTA button color on homepage",
"status": "draft",
"variants": [
{
"id": "variant-1",
"name": "Control (Blue)",
"trafficPercentage": 50,
"conversions": 0,
"visitors": 0
}
],
"createdAt": "2024-01-01T00:00:00.000Z",
"updatedAt": "2024-01-01T00:00:00.000Z"
}
]Retrieve a specific experiment by its ID.
GET /experiments/:id
Parameters:
id(string): The experiment ID
Response:
{
"id": "1",
"name": "Homepage CTA Button Test",
"description": "Testing blue vs red CTA button color on homepage",
"status": "draft",
"variants": [...],
"createdAt": "2024-01-01T00:00:00.000Z",
"updatedAt": "2024-01-01T00:00:00.000Z"
}Error Response (404):
{
"error": "Experiment not found"
}Start a draft experiment. This will change the status from 'draft' to 'running' and set the start date.
POST /experiments/:id/start
Parameters:
id(string): The experiment ID
Success Response:
{
"success": true,
"message": "Experiment started successfully",
"experiment": {
"id": "1",
"status": "running",
"startDate": "2025-09-05T19:01:28.806Z",
"updatedAt": "2025-09-05T19:01:28.806Z"
// ... other experiment fields
}
}Error Responses:
- 404: Experiment not found
{
"error": "Experiment not found"
}- 400: Invalid status transition
{
"error": "Experiment cannot be started. Current status: completed"
}- 400: Invalid traffic allocation
{
"error": "Traffic allocation must equal 100%. Current total: 90%"
}Stop a running experiment. This will change the status from 'running' to 'completed' and set the end date.
POST /experiments/:id/stop
Parameters:
id(string): The experiment ID
Success Response:
{
"success": true,
"message": "Experiment stopped successfully",
"experiment": {
"id": "1",
"status": "completed",
"endDate": "2025-09-05T19:01:31.950Z",
"updatedAt": "2025-09-05T19:01:31.950Z"
// ... other experiment fields
}
}Error Responses:
- 404: Experiment not found
{
"error": "Experiment not found"
}- 400: Invalid status transition
{
"error": "Experiment cannot be stopped. Current status: draft"
}Create a new experiment with the provided data.
POST /experiments
Request Body:
{
"name": "New Experiment",
"description": "Description of the experiment",
"variants": [
{
"name": "Control",
"trafficPercentage": 50
},
{
"name": "Treatment",
"trafficPercentage": 50
}
]
}Success Response (201):
{
"success": true,
"message": "Experiment created successfully",
"experiment": {
"id": "1704412800123",
"name": "New Experiment",
"description": "Description of the experiment",
"status": "draft",
"variants": [
{
"id": "variant-1704412800123-0",
"name": "Control",
"trafficPercentage": 50,
"conversions": 0,
"visitors": 0
}
],
"createdAt": "2024-01-04T20:00:00.123Z",
"updatedAt": "2024-01-04T20:00:00.123Z"
}
}Error Response (400):
{
"error": "Missing required fields: name, description, and variants"
}Update an experiment's status directly. This is a more flexible alternative to the specific start/stop endpoints.
PATCH /experiments/:id/status
Parameters:
id(string): The experiment ID
Request Body:
{
"status": "running"
}Valid statuses: draft, running, completed
Success Response:
{
"success": true,
"message": "Experiment status updated to running",
"experiment": {
"id": "1",
"status": "running",
"startDate": "2025-09-05T19:01:28.806Z", // Added when transitioning to running
"updatedAt": "2025-09-05T19:01:28.806Z"
// ... other experiment fields
}
}Error Responses:
- 404: Experiment not found
- 400: Invalid status value
Experiments have three possible states with the following valid transitions:
draft→running(setsstartDate)running→completed(setsendDate)- Any status → Any status (using generic status update endpoint)
draft: Experiment is created but not startedrunning: Experiment is active and collecting datacompleted: Experiment has been stopped
- All variant
trafficPercentagevalues must sum to 100% for an experiment to be startable - Traffic percentages can be decimals (e.g., 33.33%)
All error responses follow the format:
{
"error": "Error message describing what went wrong"
}Common HTTP status codes:
200: Success201: Created (for new experiments)400: Bad request (validation errors)404: Not found500: Internal server error
npm run serverThe server runs on port 3001 by default. You can change this by setting the PORT environment variable.
npm run devThis will start both the API server (port 3001) and the React frontend (port 3002) concurrently.