Skip to main content

Get Dashboard Statistics

GET /api/dashboard Retrieve aggregated statistics and analytics for the dashboard, including KPIs, recent tickets, and chart data for collection and dispatch trends.

Query Parameters

collectionCenterId
string
Filter statistics by collection center ID. If not provided, uses the active collection center from configuration.
dateFrom
string
Start date for filtering in DD/MM/YYYY format (e.g., “01/01/2026”)
dateTo
string
End date for filtering in DD/MM/YYYY format (e.g., “31/12/2026”)
month
integer
Filter by specific month (1-12)
year
integer
Filter by specific year (e.g., 2026)
generatorId
string
Filter statistics by a single generator ID
generatorIds
string
Filter statistics by multiple generator IDs (comma-separated)

Response

totalLiters
number
Total liters collected (sum of all ticket quantities)
totalDispatched
number
Total liters dispatched (sum of all dispatch quantities)
ticketCount
integer
Total number of collection tickets
totalGens
integer
Total number of unique generators (active clients)
lastFive
array
Most recent 5 tickets (sorted by created_at DESC)
chartData
array
Daily aggregated data for volume trends chart

Example Request

# Get dashboard for active center, filtered by month
curl "http://localhost:4000/api/dashboard?month=1&year=2026"
# Get dashboard for specific center and date range
curl "http://localhost:4000/api/dashboard?collectionCenterId=center-123&dateFrom=01/01/2026&dateTo=31/01/2026"
# Get dashboard filtered by generator
curl "http://localhost:4000/api/dashboard?generatorId=gen-abc&month=2&year=2026"

Example Response

{
  "totalLiters": 12450.5,
  "totalDispatched": 10200.0,
  "ticketCount": 248,
  "totalGens": 42,
  "lastFive": [
    {
      "id": "ticket-xyz",
      "ticketNumber": "AV-ARA-2026-0248",
      "date": "15/01/2026",
      "generatorName": "Restaurant El Gran Cacique",
      "quantity": 88,
      "materialType": "Aceite Vegetal Usado (AVU)",
      "materialState": "Filtrado",
      "collectorName": "Rafael Díaz",
      "vehiclePlate": "ABC123"
    }
  ],
  "chartData": [
    {
      "date": "01/01/2026",
      "litersIn": 250.0,
      "litersOut": 0
    },
    {
      "date": "02/01/2026",
      "litersIn": 180.5,
      "litersOut": 500.0
    }
  ]
}

Date Filtering Logic

The dashboard endpoint supports flexible date formats and filtering:
  • Date formats: Accepts both DD/MM/YYYY and YYYY-MM-DD formats
  • Range filtering: Use dateFrom and dateTo for custom ranges
  • Month/Year filtering: Use month and year for period filtering
  • Multiple filters: Can combine date ranges with month/year filters
The API uses PostgreSQL’s EXTRACT() function for month/year filtering and TO_DATE() for parsing dates.

Chart Data Merging

The chartData array merges collection (tickets) and dispatch data by date:
  1. Query tickets grouped by date → litersIn
  2. Query dispatches grouped by date → litersOut
  3. Merge into a single array where each date has both litersIn and litersOut values
This powers the volume trends chart in the dashboard UI.

Error Responses

StatusDescription
500Database query error

Dashboard Feature

Learn about the Dashboard UI

Tickets API

Retrieve raw ticket data

Dispatches API

Retrieve dispatch data

Configuration API

Manage active collection center

Build docs developers (and LLMs) love