API Reference

Complete API documentation for Litestore integrations

API Overview

Litestore provides a comprehensive REST API and real-time webhooks for complete platform integration. All APIs follow RESTful conventions and return JSON responses.

Authentication

All API requests require authentication using Bearer tokens:

Authorization: Bearer your-api-key

Get your API key from the dashboard under Settings > API Keys.

Rate Limiting

API requests are limited to prevent abuse:

  • 100 requests per minute for most endpoints
  • 10 requests per minute for content generation endpoints
  • Rate limit headers are included in all responses
// Rate limit headers
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 95
X-RateLimit-Reset: 1640995200

Products API

List Products

GET /api/products

Query Parameters:

  • limit (number): Number of products to return (default: 20, max: 100)
  • offset (number): Pagination offset (default: 0)
  • category (string): Filter by category ID
  • search (string): Search query
  • status (string): Filter by status (active, draft, archived)

Response:

{
  "data": [
    {
      "id": "prod-123",
      "name": "Premium Skincare Serum",
      "description": "AI-generated description...",
      "price": 49.99,
      "category": "Skincare",
      "images": ["image1.jpg", "image2.jpg"],
      "tags": ["anti-aging", "hydration"],
      "status": "active",
      "createdAt": "2024-01-01T00:00:00Z"
    }
  ],
  "total": 150,
  "limit": 20,
  "offset": 0
}

Create Product

POST /api/products

Request Body:

{
  "name": "New Product",
  "description": "Product description",
  "price": 29.99,
  "category": "Electronics",
  "images": ["image1.jpg"],
  "tags": ["wireless", "bluetooth"],
  "generateDescription": true
}

Response:

{
  "id": "prod-456",
  "name": "New Product",
  "description": "AI-generated description...",
  "price": 29.99,
  "status": "draft",
  "createdAt": "2024-01-15T10:30:00Z"
}

Get Product

GET /api/products/{id}

Update Product

PUT /api/products/{id}

Delete Product

DELETE /api/products/{id}

Creator Content API

Submit Creator Content

POST /api/creators/content

Request Body:

{
  "creatorId": "creator-123",
  "title": "Amazing Product Review",
  "description": "My honest experience...",
  "media": [
    {
      "type": "image",
      "url": "review-photo.jpg",
      "caption": "Before and after results"
    }
  ],
  "products": ["prod-123", "prod-456"],
  "tags": ["review", "transformation"]
}

Response:

{
  "id": "content-789",
  "status": "pending_review",
  "moderation": {
    "aiAnalysis": {
      "spamScore": 0.02,
      "qualityScore": 8.5,
      "sentiment": "positive"
    }
  },
  "createdAt": "2024-01-15T11:00:00Z"
}

List Creator Content

GET /api/creators/content

Query Parameters:

  • creatorId (string): Filter by creator
  • status (string): Filter by status (pending, approved, rejected)
  • productId (string): Filter by associated product

Moderate Content

POST /api/creators/content/{id}/moderate

Request Body:

{
  "action": "approve",
  "feedback": "Great content!",
  "modifications": {
    "title": "Approved: Amazing Product Review"
  }
}

AI API

Generate Product Description

POST /api/ai/generate-description

Request Body:

{
  "productName": "Wireless Bluetooth Headphones",
  "features": ["Noise cancellation", "20hr battery"],
  "targetAudience": "music enthusiasts",
  "brandVoice": "professional",
  "maxLength": 200
}

Response:

{
  "description": "Experience unparalleled sound quality with our premium wireless Bluetooth headphones...",
  "metadata": {
    "tokens": 145,
    "processingTime": 2.3,
    "model": "gpt-4"
  }
}

Analyze Content

POST /api/ai/analyze-content

Request Body:

{
  "content": "This product is amazing!",
  "analysis": ["sentiment", "spam", "quality"]
}

Response:

{
  "sentiment": "positive",
  "spamScore": 0.01,
  "qualityScore": 9.2,
  "language": "en",
  "confidence": 0.98
}

Suggest Categories

POST /api/ai/suggest-categories

Request Body:

{
  "productTitle": "Organic Green Tea",
  "description": "Premium loose leaf tea",
  "existingCategories": ["Tea", "Beverages", "Health"]
}

Response:

{
  "suggestions": [
    "Organic Tea",
    "Green Tea",
    "Health & Wellness",
    "Beverages"
  ],
  "confidence": 0.89
}

Reviews API

Submit Review

POST /api/products/{id}/reviews

Request Body:

{
  "rating": 5,
  "title": "Life-changing product!",
  "content": "This product exceeded all my expectations...",
  "verified": true,
  "photos": ["review-photo1.jpg"]
}

List Product Reviews

GET /api/products/{id}/reviews

Query Parameters:

  • rating (number): Filter by rating (1-5)
  • verified (boolean): Only verified purchases
  • sort (string): Sort by newest, oldest, helpful

Mark Review Helpful

POST /api/reviews/{id}/helpful

Analytics API

Get Product Analytics

GET /api/analytics/products/{id}

Query Parameters:

  • period (string): Time period (7d, 30d, 90d, 1y)
  • metrics (array): Metrics to include

Response:

{
  "views": 15420,
  "purchases": 234,
  "conversionRate": 0.015,
  "avgOrderValue": 67.50,
  "topReferrers": [
    { "source": "creator-content", "visits": 3240 },
    { "source": "social-media", "visits": 2100 }
  ],
  "period": "30d"
}

Get Creator Analytics

GET /api/analytics/creators/{id}

Response:

{
  "contentCount": 45,
  "totalViews": 125000,
  "totalClicks": 8900,
  "totalConversions": 234,
  "totalCommission": 1247.50,
  "avgEngagement": 0.071,
  "topContent": [
    {
      "id": "content-123",
      "title": "Honest Review",
      "views": 8500,
      "conversions": 67
    }
  ]
}

Webhooks

Litestore sends real-time notifications via webhooks for important events.

Webhook Configuration

Set up webhooks in your dashboard under Settings > Webhooks:

const webhookConfig = {
  url: "https://your-app.com/webhooks/litestore",
  events: [
    "content.submitted",
    "content.approved",
    "review.created",
    "product.purchased",
    "commission.earned"
  ],
  secret: "your-webhook-secret"
}

Event Types

Content Events

{
  "event": "content.submitted",
  "data": {
    "contentId": "content-123",
    "creatorId": "creator-456",
    "productIds": ["prod-789"],
    "status": "pending_review",
    "submittedAt": "2024-01-15T10:30:00Z"
  }
}
{
  "event": "content.approved",
  "data": {
    "contentId": "content-123",
    "approvedBy": "admin-789",
    "approvedAt": "2024-01-15T11:00:00Z",
    "commission": 25.50
  }
}

Review Events

{
  "event": "review.created",
  "data": {
    "reviewId": "review-456",
    "productId": "prod-123",
    "rating": 5,
    "verified": true,
    "createdAt": "2024-01-15T12:00:00Z"
  }
}

Purchase Events

{
  "event": "product.purchased",
  "data": {
    "orderId": "order-789",
    "productId": "prod-123",
    "quantity": 1,
    "revenue": 49.99,
    "referrer": {
      "type": "creator-content",
      "contentId": "content-123",
      "creatorId": "creator-456"
    },
    "purchasedAt": "2024-01-15T14:30:00Z"
  }
}

Commission Events

{
  "event": "commission.earned",
  "data": {
    "commissionId": "commission-101",
    "creatorId": "creator-456",
    "contentId": "content-123",
    "productId": "prod-123",
    "amount": 4.99,
    "status": "pending",
    "earnedAt": "2024-01-15T14:30:00Z"
  }
}

Webhook Security

All webhooks include a signature for verification:

const signature = request.headers['x-litestore-signature'];
const expectedSignature = crypto
  .createHmac('sha256', webhookSecret)
  .update(request.body)
  .digest('hex');

if (signature === expectedSignature) {
  // Valid webhook
  processWebhook(request.body);
}

Error Handling

All API errors follow a consistent format:

{
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Invalid product data",
    "details": {
      "field": "price",
      "issue": "must be positive number"
    }
  }
}

Common Error Codes

  • VALIDATION_ERROR: Invalid request data
  • AUTHENTICATION_ERROR: Invalid or missing API key
  • AUTHORIZATION_ERROR: Insufficient permissions
  • NOT_FOUND: Resource not found
  • RATE_LIMITED: Too many requests
  • SERVER_ERROR: Internal server error

SDKs and Libraries

JavaScript/TypeScript SDK

npm install litestore-sdk
import { Litestore } from 'litestore-sdk';

const client = new Litestore({
  apiKey: 'your-api-key',
  baseUrl: 'https://api.litestore.com'
});

// Create a product
const product = await client.products.create({
  name: 'New Product',
  price: 29.99,
  generateDescription: true
});

Community SDKs

  • Python: pip install litestore-python
  • PHP: composer require litestore/litestore-php
  • Ruby: gem install litestore

Best Practices

Rate Limiting

Implement exponential backoff for rate-limited requests:

async function apiCallWithRetry(endpoint, options, maxRetries = 3) {
  for (let i = 0; i < maxRetries; i++) {
    try {
      const response = await fetch(endpoint, options);
      if (response.status === 429) {
        const resetTime = response.headers.get('X-RateLimit-Reset');
        const waitTime = Math.pow(2, i) * 1000; // Exponential backoff
        await new Promise(resolve => setTimeout(resolve, waitTime));
        continue;
      }
      return response;
    } catch (error) {
      if (i === maxRetries - 1) throw error;
    }
  }
}

Webhook Reliability

Implement webhook retry logic and idempotency:

const processedEvents = new Set();

async function handleWebhook(event) {
  if (processedEvents.has(event.id)) {
    return; // Already processed
  }

  try {
    await processEvent(event);
    processedEvents.add(event.id);
  } catch (error) {
    // Log error and retry later
    console.error('Webhook processing failed:', error);
    // Implement retry queue
  }
}

Error Handling

Always handle API errors gracefully:

async function createProduct(productData) {
  try {
    const response = await fetch('/api/products', {
      method: 'POST',
      headers: {
        'Authorization': `Bearer ${apiKey}`,
        'Content-Type': 'application/json'
      },
      body: JSON.stringify(productData)
    });

    if (!response.ok) {
      const error = await response.json();
      throw new Error(`API Error: ${error.error.message}`);
    }

    return await response.json();
  } catch (error) {
    console.error('Product creation failed:', error);
    // Implement fallback or user notification
  }
}

Need Help?

Check our troubleshooting guide for common integration issues, or join our Discord community for developer support.

On this page