REST API
Analytics

Analytics

All routes under /api/v1/analytics require authentication + Owner role. All accept date_from and date_to query parameters (ISO format).


GET /analytics/overview

Modular dashboard overview with section selection.

Auth: Required + Owner

Query Parameters:

ParameterTypeDescription
sectionsstringComma-separated: kpis, trend, mix, products
date_fromstringISO date
date_tostringISO date

Response:

{
  "success": true,
  "data": {
    "kpis": { "revenue": 5250000, "transactions": 180, ... },
    "trend": { "labels": [...], "values": [...] },
    "payment_mix": { "Cash": 60, "M-Pesa": 35, "Credit": 5 },
    "top_products": [ ... ]
  }
}

GET /analytics/summary

KPI summary for a date range.

Auth: Required + Owner

Response:

{
  "success": true,
  "data": {
    "revenue": 5250000,
    "transaction_count": 180,
    "average_ticket": 29167,
    "profit": 1575000,
    "items_sold": 450,
    "refund_count": 3
  }
}

GET /analytics/trend

Revenue trend over time.

Auth: Required + Owner

Response:

{
  "success": true,
  "data": {
    "trend": [
      { "date": "2024-01-01", "revenue": 450000, "count": 15 },
      { "date": "2024-01-02", "revenue": 520000, "count": 18 }
    ],
    "date_from": "2024-01-01",
    "date_to": "2024-01-31"
  }
}

GET /analytics/payment-mix

Payment method distribution.

Auth: Required + Owner

Response:

{
  "success": true,
  "data": {
    "payment_mix": {
      "Cash": 3150000,
      "M-Pesa": 1837500,
      "Credit": 262500
    }
  }
}

GET /analytics/top-products

Top selling products by revenue.

Auth: Required + Owner

Query: limit (1-50, default: 10)

Response:

{
  "success": true,
  "data": {
    "top_products": [
      {
        "product_id": "uuid",
        "name": "Pepsi 500ml",
        "qty_sold": 120,
        "revenue": 180000,
        "profit": 84000
      }
    ],
    "date_from": "2024-01-01",
    "date_to": "2024-01-31"
  }
}

GET /analytics/sales

Full sales report combining KPIs, trend, and breakdown.

Auth: Required + Owner


GET /analytics/products

Product performance analytics.

Auth: Required + Owner

Query: category, sort


GET /analytics/customers

Customer analytics.

Auth: Required + Owner


GET /analytics/cashflow

Cashflow analysis.

Auth: Required + Owner


GET /analytics/dashboard

Real-time dashboard snapshot.

Auth: Required + Owner