REST API Reference

ABSPLITTEST REST API Documentation

The ABSPLITTEST plugin provides a comprehensive REST API for programmatic access to A/B testing functionality. All endpoints require authentication and the edit_posts capability.

Base URL

https://your-site.com/wp-json/bt-bb-ab/v1/

Authentication

Use WordPress Application Passwords for authentication:

  1. Go to Users → Profile
  2. Scroll to Application Passwords
  3. Create a new application password
  4. Use Basic Auth with your username and application password

Available Endpoints

1. Create Test

POST /wp-json/bt-bb-ab/v1/create-test

Request Body:

{
  "test_title": "My A/B Test",
  "test_type": "magic",
  "status": "draft",
  "magic_definition": [
    {
      "original": "Old Text",
      "variations": ["New Text 1", "New Text 2"]
    }
  ],
  "conversion_type": "click",
  "conversion_selector": ".buy-button"
}

Response:

{
  "success": true,
  "test_id": 123,
  "test_type": "magic",
  "edit_url": "https://your-site.com/wp-admin/post.php?post=123&action=edit",
  "message": "Test created successfully"
}

2. List Tests

GET /wp-json/bt-bb-ab/v1/list-tests

Response:

{
  "success": true,
  "count": 5,
  "tests": [
    {
      "id": 123,
      "title": "Homepage Hero Test",
      "type": "magic",
      "status": "publish",
      "visits": 1500,
      "conversions": 75,
      "conversion_rate": 5.0
    }
  ]
}

3. Get Test Results

GET /wp-json/bt-bb-ab/v1/test-results/{id}

Response:

{
  "success": true,
  "test": {
    "id": 123,
    "title": "Homepage Hero Test",
    "type": "magic",
    "status": "publish",
    "visits": 1500,
    "conversions": 75,
    "conversion_rate": 5.0,
    "variations": {
      "control": {
        "visits": 750,
        "conversions": 30,
        "conversion_rate": 4.0
      },
      "variation_1": {
        "visits": 750,
        "conversions": 45,
        "conversion_rate": 6.0
      }
    }
  }
}

4. Update Test Status

POST /wp-json/bt-bb-ab/v1/update-test-status

Request Body:

{
  "test_id": 123,
  "status": "publish"
}

Response:

{
  "success": true,
  "test_id": 123,
  "status": "publish",
  "message": "Test status updated successfully"
}

Example: cURL Request

curl -X POST https://your-site.com/wp-json/bt-bb-ab/v1/create-test 
  -u "username:application_password" 
  -H "Content-Type: application/json" 
  -d '{
    "test_title": "My Test",
    "test_type": "magic",
    "status": "draft"
  }'

Example: JavaScript/Fetch

const response = await fetch('https://your-site.com/wp-json/bt-bb-ab/v1/list-tests', {
  headers: {
    'Authorization': 'Basic ' + btoa('username:application_password')
  }
});
const data = await response.json();

Error Handling

All endpoints return standard HTTP status codes:

  • 200 – Success
  • 400 – Bad Request (invalid parameters)
  • 401 – Unauthorized (authentication failed)
  • 403 – Forbidden (insufficient permissions)
  • 404 – Not Found (test doesn’t exist)
  • 500 – Server Error

Rate Limiting

The REST API follows WordPress core rate limiting. For high-volume usage, consider implementing request throttling on your end.

See Also

Leave a Comment

You must be logged in to post a comment.