The Peakees API provides RESTful endpoints for managing products, cart operations, user authentication, and order processing. All endpoints follow consistent patterns and return JSON responses.
- JWT Tokens - Supabase Auth JWT tokens in Authorization header
- Session Cookies - httpOnly cookies for web clients
- API Keys - Service-to-service authentication
Authorization: Bearer <jwt_token>Authenticate user with email and password.
POST /api/auth/login
Content-Type: application/json
{
"email": "user@example.com",
"password": "password123"
}Response:
{
"success": true,
"data": {
"user": {
"id": "uuid",
"email": "user@example.com",
"name": "John Doe"
},
"session": {
"access_token": "jwt_token",
"refresh_token": "refresh_token",
"expires_at": 1234567890
}
}
}Register new user account.
POST /api/auth/register
Content-Type: application/json
{
"email": "user@example.com",
"password": "password123",
"name": "John Doe"
}Logout current user session.
POST /api/auth/logout
Authorization: Bearer <jwt_token>Retrieve products with filtering and pagination.
GET /api/products?search=query&category=id&sort=price&order=asc&page=1&limit=12Query Parameters:
search(string) - Search query for product name/descriptioncategory(string) - Category ID filtersort(string) - Sort field:name,price,created_at,updated_atorder(string) - Sort order:asc,descpage(number) - Page number (default: 1)limit(number) - Items per page (default: 12, max: 100)featured(boolean) - Filter featured productsnew(boolean) - Filter new productssale(boolean) - Filter sale products
Response:
{
"success": true,
"data": {
"products": [
{
"id": "uuid",
"name": "Product Name",
"description": "Product description",
"price": 99.99,
"discount_percent": 10,
"image_url": "https://example.com/image.jpg",
"inventory_count": 50,
"is_featured": true,
"is_new": false,
"category": {
"id": "uuid",
"name": "Category Name"
},
"created_at": "2024-01-01T00:00:00Z",
"updated_at": "2024-01-01T00:00:00Z"
}
],
"pagination": {
"page": 1,
"limit": 12,
"total": 100,
"totalPages": 9,
"hasNext": true,
"hasPrev": false
}
}
}Retrieve single product by ID.
GET /api/products/uuidResponse:
{
"success": true,
"data": {
"id": "uuid",
"name": "Product Name",
"description": "Detailed product description",
"price": 99.99,
"discount_percent": 10,
"image_url": "https://example.com/image.jpg",
"images": ["https://example.com/image1.jpg", "https://example.com/image2.jpg"],
"inventory_count": 50,
"is_featured": true,
"is_new": false,
"specifications": {
"weight": "1.5kg",
"dimensions": "30x20x10cm",
"material": "Cotton"
},
"category": {
"id": "uuid",
"name": "Category Name",
"slug": "category-name"
},
"related_products": [
{
"id": "uuid",
"name": "Related Product",
"price": 79.99,
"image_url": "https://example.com/related.jpg"
}
],
"created_at": "2024-01-01T00:00:00Z",
"updated_at": "2024-01-01T00:00:00Z"
}
}Create new product.
POST /api/products
Authorization: Bearer <admin_jwt_token>
Content-Type: application/json
{
"name": "New Product",
"description": "Product description",
"price": 99.99,
"category_id": "uuid",
"inventory_count": 100,
"is_featured": false,
"specifications": {
"weight": "1kg"
}
}Update existing product.
PUT /api/products/uuid
Authorization: Bearer <admin_jwt_token>
Content-Type: application/json
{
"name": "Updated Product Name",
"price": 89.99,
"inventory_count": 75
}Delete product.
DELETE /api/products/uuid
Authorization: Bearer <admin_jwt_token>Retrieve user's cart items.
GET /api/cart
Authorization: Bearer <jwt_token>Response:
{
"success": true,
"data": {
"items": [
{
"id": "uuid",
"product_id": "uuid",
"quantity": 2,
"product": {
"id": "uuid",
"name": "Product Name",
"price": 99.99,
"discount_percent": 10,
"image_url": "https://example.com/image.jpg",
"inventory_count": 50
},
"created_at": "2024-01-01T00:00:00Z"
}
],
"total": 179.98,
"itemCount": 2,
"subtotal": 199.98,
"discount": 19.98
}
}Add item to cart.
POST /api/cart/add
Authorization: Bearer <jwt_token>
Content-Type: application/json
{
"product_id": "uuid",
"quantity": 1
}Response:
{
"success": true,
"data": {
"id": "uuid",
"product_id": "uuid",
"quantity": 1,
"message": "Item added to cart"
}
}Update cart item quantity.
PUT /api/cart/update
Authorization: Bearer <jwt_token>
Content-Type: application/json
{
"id": "cart_item_uuid",
"quantity": 3
}Remove item from cart.
DELETE /api/cart/remove
Authorization: Bearer <jwt_token>
Content-Type: application/json
{
"id": "cart_item_uuid"
}Sync cart data (for cross-device synchronization).
POST /api/cart/sync
Authorization: Bearer <jwt_token>
Content-Type: application/json
{
"items": [
{
"product_id": "uuid",
"quantity": 2
}
]
}Clear all items from cart.
DELETE /api/cart/clear
Authorization: Bearer <jwt_token>Retrieve all product categories.
GET /api/categoriesResponse:
{
"success": true,
"data": [
{
"id": "uuid",
"name": "Electronics",
"slug": "electronics",
"description": "Electronic products",
"image_url": "https://example.com/category.jpg",
"product_count": 150,
"parent_id": null,
"children": [
{
"id": "uuid",
"name": "Smartphones",
"slug": "smartphones",
"product_count": 50
}
]
}
]
}Retrieve single category with products.
GET /api/categories/uuid?page=1&limit=12Response:
{
"success": true,
"data": {
"category": {
"id": "uuid",
"name": "Electronics",
"description": "Electronic products",
"image_url": "https://example.com/category.jpg"
},
"products": [
{
"id": "uuid",
"name": "Product Name",
"price": 99.99,
"image_url": "https://example.com/product.jpg"
}
],
"pagination": {
"page": 1,
"limit": 12,
"total": 50,
"totalPages": 5
}
}
}Search products with advanced filtering.
GET /api/search?q=query&category=id&min_price=10&max_price=100Query Parameters:
q(string) - Search querycategory(string) - Category filtermin_price(number) - Minimum price filtermax_price(number) - Maximum price filtersort(string) - Sort fieldorder(string) - Sort order
Get search suggestions for autocomplete.
GET /api/search/suggestions?q=partial_query&limit=5Response:
{
"success": true,
"data": {
"suggestions": ["iPhone 15", "iPhone 14", "iPhone case"],
"products": [
{
"id": "uuid",
"name": "iPhone 15 Pro",
"price": 999.99,
"image_url": "https://example.com/iphone.jpg"
}
]
}
}Track custom analytics events.
POST /api/analytics/events
Content-Type: application/json
{
"event": "product_view",
"data": {
"product_id": "uuid",
"category": "electronics",
"price": 99.99
},
"timestamp": 1234567890,
"session_id": "session_uuid",
"user_id": "user_uuid"
}Track cart abandonment events.
POST /api/analytics/cart-abandonment
Content-Type: application/json
{
"event_id": "abandon_uuid",
"timestamp": 1234567890,
"total": 199.98,
"item_count": 3,
"user_id": "user_uuid",
"items": [
{
"product_id": "uuid",
"quantity": 2,
"price": 99.99
}
]
}Handle Stripe webhook events.
POST /api/webhooks/stripe
Stripe-Signature: signature_header
Content-Type: application/json
{
"id": "evt_uuid",
"type": "checkout.session.completed",
"data": {
"object": {
"id": "cs_uuid",
"payment_status": "paid",
"customer_email": "user@example.com"
}
}
}All API errors follow a consistent format:
{
"success": false,
"error": {
"code": "VALIDATION_ERROR",
"message": "Invalid input data",
"details": {
"field": "email",
"issue": "Invalid email format"
}
}
}200- Success201- Created400- Bad Request (validation error)401- Unauthorized (authentication required)403- Forbidden (insufficient permissions)404- Not Found409- Conflict (duplicate resource)422- Unprocessable Entity (business logic error)429- Too Many Requests (rate limited)500- Internal Server Error
VALIDATION_ERROR- Input validation failedAUTHENTICATION_REQUIRED- User must be authenticatedINSUFFICIENT_PERMISSIONS- User lacks required permissionsRESOURCE_NOT_FOUND- Requested resource doesn't existDUPLICATE_RESOURCE- Resource already existsINVENTORY_INSUFFICIENT- Not enough stock availableRATE_LIMIT_EXCEEDED- Too many requests
- Anonymous users: 100 requests per hour
- Authenticated users: 1000 requests per hour
- Admin users: 5000 requests per hour
X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 999
X-RateLimit-Reset: 1234567890{
"success": true,
"data": {
"id": "uuid",
"name": "Product Name"
},
"meta": {
"timestamp": "2024-01-01T00:00:00Z",
"version": "1.0"
}
}{
"success": false,
"error": {
"code": "VALIDATION_ERROR",
"message": "Validation failed",
"details": [
{
"field": "email",
"message": "Email is required"
}
]
},
"meta": {
"timestamp": "2024-01-01T00:00:00Z",
"request_id": "req_uuid"
}
}Use the provided test utilities for API testing:
// Test helper
import { createTestClient } from '@/lib/test-utils';
const client = createTestClient();
test('should fetch products', async () => {
const response = await client.get('/api/products');
expect(response.status).toBe(200);
expect(response.data.success).toBe(true);
});Mock data is available for testing:
import { mockProducts, mockUser } from '@/lib/test-data';
// Use in tests
const product = mockProducts[0];
const user = mockUser();This API reference provides comprehensive documentation for all available endpoints in the Peakees e-commerce platform. For implementation examples, see the respective feature documentation.