API Reference
Internal API endpoints used by the admin panel and available for integration.
Authentication
All API endpoints require an active PHP session (logged-in user). There is no public API key authentication yet — all calls must originate from the admin panel.
AI Endpoints
POST /api/ai-generate.php?action=generate
Generate a complete website structure from a text description.
// Request body
{
"description": "A school website for Sunrise Academy...",
"category": "school" // optional hint
}
// Response
{
"success": true,
"site": {
"site_name": "Sunrise Academy",
"tagline": "Excellence in Education",
"type": "school",
"colors": { "primary": "#1e40af", "secondary": "#f59e0b" },
"font": "Poppins",
"pages": {
"home": { "title": "Home", "sections": [...] },
"about": { "title": "About Us", "sections": [...] }
}
},
"source": "ai" // or "fallback"
}
POST /api/ai-generate.php?action=create
Save a generated site to the database and generate static HTML files.
// Request body
{
"site": { ...site object from generate endpoint... }
}
// Response
{
"success": true,
"site_id": 42,
"slug": "sunrise-academy",
"url": "sites/sunrise-academy/index.html",
"edit_url": "visual-editor.php?site_id=42&page=home"
}
POST /api/ai-generate.php?action=expand
Expand a short description into a detailed brief.
// Request body
{ "description": "A school website", "category": "school" }
// Response
{ "success": true, "description": "A comprehensive school website for..." }
Theme Endpoint
POST /api/update-theme.php
Update a site's theme colors and regenerate all pages.
// Request body
{
"site_id": 42,
"primary": "#1d4ed8",
"secondary": "#f59e0b",
"font": "Inter"
}
// Response
{
"success": true,
"message": "Theme updated and site regenerated.",
"theme": { "primary": "#1d4ed8", "secondary": "#f59e0b", "font": "Inter" }
}
Contact Endpoint
POST /api/contact.php
Submit a contact form. Used by the generated static sites.
// Request body (form data or JSON)
{
"site_id": 42,
"name": "John Doe",
"email": "john@example.com",
"phone": "+91 9876543210",
"message": "Hello, I'd like to enquire about..."
}
// Response
{ "success": true, "message": "Message sent successfully." }
Products API
GET /api/products.php?site_id=X
Returns all active products for a site (used by the shop frontend).
// Response
{
"success": true,
"products": [
{
"id": 1, "name": "Product Name", "slug": "product-name",
"price": 999, "sale_price": null, "stock": 50,
"category": "general", "images": [...], "description": "..."
}
]
}
Orders API
POST /api/orders.php
Create a new order (called from checkout page).
// Request body
{
"site_id": 42,
"items": [{ "product_id": 1, "quantity": 2 }],
"customer": { "name": "...", "email": "...", "phone": "...", "address": "..." },
"payment_method": "online", // or "cod"
"coupon_code": "SAVE20" // optional
}