Overview
ThegetOccupancyHistory endpoint retrieves historical hourly snapshots of parking occupancy data. It supports time range filtering and optional zone-specific queries for detailed analytics.
Endpoint
Authentication
CORS-enabled endpoint with wildcard origin (*). No authentication required for read access.
Query Parameters
Number of days of history to retrieve. Valid range: 1-30. Values outside this range are clamped.
Optional zone ID to filter results (e.g., “zone_1764307623391”). If provided, returns detailed zone-specific data. If omitted, returns summary for all zones.
Response
Always
true for successful requestsActual number of days returned (after clamping 1-30)
The zone ID filter applied, or
null if showing all zonesNumber of hourly snapshots returned
ISO 8601 timestamp of the start of the time range
ISO 8601 timestamp of the end of the time range
Array of hourly snapshot objects
Unique hour identifier in format
YYYY-MM-DD-HH (UTC)Unix timestamp in milliseconds
Global parking statistics across all zones:
free: Number of available spotsoccupied: Number of occupied spotsreserved: Number of reserved spotstotal: Total number of spotsoccupancyPct: Occupancy percentage (0-100)
Zone-specific statistics (only present when
zoneId parameter is provided)Summary array of all zones (only present when
zoneId is NOT provided). Each element contains:id: Zone identifieroccupancyPct: Occupancy percentagefree: Available spotsoccupied: Occupied spotsreserved: Reserved spotstotal: Total spots
Success Response
- 200 OK - Returns occupancy history data
- 204 No Content - OPTIONS preflight response
Error Responses
- 405 Method Not Allowed - Request method is not GET
- 500 Internal Server Error - Database or server error
Code Examples
Get Last 7 Days (All Zones)
Get Zone-Specific Data
Response Examples
All Zones Summary
Single Zone Detail
Data Visualization Examples
Chart.js Line Graph
Peak Hours Analysis
Time Range Clamping
Thedays parameter is validated and clamped:
days=0→ Returns 1 daydays=45→ Returns 30 days (max)days=invalid→ Returns 1 day (default)
Performance Considerations
- Indexed Query: Uses Firestore index on
tsfield for efficient time-based queries - Payload Optimization: Zone summary excludes spot-level details to reduce response size
- Retention Policy: Historical data is automatically cleaned by Save Hourly Snapshot after 30 days
Related Endpoints
- Save Hourly Snapshot - Create occupancy snapshots (called by Cloud Scheduler)
- Get Zones - Fetch zone metadata
- Get Parking Status - Real-time status vs historical data