Returns sensor readings averaged over time intervals for chart rendering. For a daily view, readings are averaged per hour over the last 24 hours. For weekly and monthly views, readings are averaged per calendar day. This endpoint requires Bearer token authentication.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/GaelCeballos/Smart_Enviro_Backend/llms.txt
Use this file to discover all available pages before exploring further.
Endpoint
GET/api/sensor-data/history
Auth: Bearer token required (Sanctum)
This route is defined before the
apiResource registration in routes/api.php to avoid route conflicts with the show action. It requires authentication with a Sanctum Bearer token — requests without a valid token will receive a 401 Unauthenticated response.Query Parameters
The integer database ID of the device whose readings should be aggregated.
The integer database ID of the sensor type to aggregate. This endpoint expects the integer ID, not the
metric_key string.The time window and grouping strategy for aggregation. Accepted values:
day, week, month.Period Reference
| Period | Window | Grouping | SQL Aggregation |
|---|---|---|---|
day | Last 24 hours | Per hour | AVG grouped by DATE_FORMAT(recorded_at, '%H:00') |
week | Last 7 days | Per calendar day | AVG grouped by DATE(recorded_at) |
month | Last 30 days | Per calendar day | AVG grouped by DATE(recorded_at) |
Example Request
Responses
200 OK
Returns the averaged data points ordered chronologically by label (ascending). Only time slots that have at least one reading are included — empty hours or days are omitted.Always
"success" on a 200 response.Echoes back the requested
period value ("day", "week", or "month").The number of aggregated data points returned in the
data array. Equals the number of distinct hours or days that had at least one reading in the time window.Array of aggregated data point objects, ordered ascending by
label.401 Unauthenticated
No Bearer token was provided or the token is invalid/expired.422 Unprocessable Entity
One or more required query parameters (device_id, sensor_type_id, period) are missing, or period is not one of day, week, month.