Skip to main content

Get Dashboard Statistics

GET /api/admin/stats
Retrieves comprehensive dashboard statistics including revenue metrics, order counts, user statistics, recent sales, top products, and chart data for the last 180 days. Authentication: Admin access required

Response

success
boolean
Indicates if the request was successful
stats
object
recentSales
array
Array of the 8 most recent orders with populated user information
topProducts
array
Top 3 products by quantity sold (from completed orders) with trend data
chartData
array
Daily revenue data for the last 180 days

Response Example

{
  "success": true,
  "stats": {
    "totals": {
      "totalRevenue": 50000,
      "totalOrders": 245,
      "activeUsers": 150,
      "totalUsers": 180,
      "networkFees": 500
    },
    "trends": {
      "revenueChange": "+15.3%",
      "ordersChange": "+8.2%",
      "usersChange": "+12.5%",
      "feesChange": "+15.0%"
    },
    "last30Days": {
      "totalRevenue": 15000,
      "totalOrders": 75,
      "networkFees": 150
    },
    "statusCounts": {
      "completed": 200,
      "pending": 30,
      "refunded": 15
    }
  },
  "recentSales": [
    {
      "orderId": "ORD-123456",
      "userId": {
        "username": "john_doe",
        "email": "[email protected]"
      },
      "total": 299.99,
      "status": "completed",
      "createdAt": "2026-03-04T10:30:00.000Z",
      "transactionHash": "0xabc123...",
      "products": []
    }
  ],
  "topProducts": [
    {
      "_id": "prod123",
      "name": "Premium Package",
      "quantitySold": 150,
      "revenue": 15000,
      "trend": "+20.5%"
    }
  ],
  "chartData": [
    {
      "date": "2025-09-06",
      "revenue": 1200
    },
    {
      "date": "2025-09-07",
      "revenue": 0
    }
  ]
}

Error Response

{
  "error": "Error message"
}

Build docs developers (and LLMs) love