API Documentation
Welcome to the Agrometrix API. Use the following endpoints to access plot and sensor data.
Authentication
All API requests must be authenticated using a Bearer token in the Authorization
header. Contact the administrator to obtain an API key.
Authorization: Bearer YOUR_API_KEY
Sensor ID Distribution
The sensor IDs are distributed across the plots and sensor types as follows. Use these IDs to query specific sensor data.
Sensor ID Cheat Sheet
Plot | Sensor ID | Sensor Type | Depth |
---|---|---|---|
Plot Alpha (#1) | 1 | Temperature | 5 cm |
Plot Alpha (#1) | 2 | Humidity | 5 cm |
Plot Alpha (#1) | 73 | Soil EC | 5 cm |
Plot Alpha (#1) | 3 | Temperature | 20 cm |
Plot Alpha (#1) | 4 | Humidity | 20 cm |
Plot Alpha (#1) | 74 | Soil EC | 20 cm |
Plot Alpha (#1) | 5 | Temperature | 40 cm |
Plot Alpha (#1) | 6 | Humidity | 40 cm |
Plot Alpha (#1) | 75 | Soil EC | 40 cm |
Plot Alpha (#1) | 7 | Temperature | 60 cm |
Plot Alpha (#1) | 8 | Humidity | 60 cm |
Plot Alpha (#1) | 76 | Soil EC | 60 cm |
Plot Alpha (#1) | 9 | Temperature | 80 cm |
Plot Alpha (#1) | 10 | Humidity | 80 cm |
Plot Alpha (#1) | 77 | Soil EC | 80 cm |
Plot Alpha (#1) | 11 | Temperature | 100 cm |
Plot Alpha (#1) | 12 | Humidity | 100 cm |
Plot Alpha (#1) | 78 | Soil EC | 100 cm |
Plot Alpha (#1) | 13 | Nitrogen | 6.3 cm |
Plot Alpha (#1) | 14 | Phosphorus | 6.3 cm |
Plot Alpha (#1) | 15 | Potassium | 6.3 cm |
Plot Beta (#44) | 19 | Temperature | 5 cm |
Plot Beta (#44) | 20 | Humidity | 5 cm |
Plot Beta (#44) | 79 | Soil EC | 5 cm |
Plot Beta (#44) | 21 | Temperature | 20 cm |
Plot Beta (#44) | 22 | Humidity | 20 cm |
Plot Beta (#44) | 80 | Soil EC | 20 cm |
Plot Beta (#44) | 23 | Temperature | 40 cm |
Plot Beta (#44) | 24 | Humidity | 40 cm |
Plot Beta (#44) | 81 | Soil EC | 40 cm |
Plot Beta (#44) | 25 | Temperature | 60 cm |
Plot Beta (#44) | 26 | Humidity | 60 cm |
Plot Beta (#44) | 82 | Soil EC | 60 cm |
Plot Beta (#44) | 27 | Temperature | 80 cm |
Plot Beta (#44) | 28 | Humidity | 80 cm |
Plot Beta (#44) | 83 | Soil EC | 80 cm |
Plot Beta (#44) | 29 | Temperature | 100 cm |
Plot Beta (#44) | 30 | Humidity | 100 cm |
Plot Beta (#44) | 84 | Soil EC | 100 cm |
Plot Beta (#44) | 31 | Nitrogen | 6.3 cm |
Plot Beta (#44) | 32 | Phosphorus | 6.3 cm |
Plot Beta (#44) | 33 | Potassium | 6.3 cm |
Plot Gamma (#52) | 37 | Temperature | 5 cm |
Plot Gamma (#52) | 38 | Humidity | 5 cm |
Plot Gamma (#52) | 85 | Soil EC | 5 cm |
Plot Gamma (#52) | 39 | Temperature | 20 cm |
Plot Gamma (#52) | 40 | Humidity | 20 cm |
Plot Gamma (#52) | 86 | Soil EC | 20 cm |
Plot Gamma (#52) | 41 | Temperature | 40 cm |
Plot Gamma (#52) | 42 | Humidity | 40 cm |
Plot Gamma (#52) | 87 | Soil EC | 40 cm |
Plot Gamma (#52) | 43 | Temperature | 60 cm |
Plot Gamma (#52) | 44 | Humidity | 60 cm |
Plot Gamma (#52) | 88 | Soil EC | 60 cm |
Plot Gamma (#52) | 45 | Temperature | 80 cm |
Plot Gamma (#52) | 46 | Humidity | 80 cm |
Plot Gamma (#52) | 89 | Soil EC | 80 cm |
Plot Gamma (#52) | 47 | Temperature | 100 cm |
Plot Gamma (#52) | 48 | Humidity | 100 cm |
Plot Gamma (#52) | 90 | Soil EC | 100 cm |
Plot Gamma (#52) | 49 | Nitrogen | 6.3 cm |
Plot Gamma (#52) | 50 | Phosphorus | 6.3 cm |
Plot Gamma (#52) | 51 | Potassium | 6.3 cm |
Plot Delta (#23) | 55 | Temperature | 5 cm |
Plot Delta (#23) | 56 | Humidity | 5 cm |
Plot Delta (#23) | 91 | Soil EC | 5 cm |
Plot Delta (#23) | 57 | Temperature | 20 cm |
Plot Delta (#23) | 58 | Humidity | 20 cm |
Plot Delta (#23) | 92 | Soil EC | 20 cm |
Plot Delta (#23) | 59 | Temperature | 40 cm |
Plot Delta (#23) | 60 | Humidity | 40 cm |
Plot Delta (#23) | 93 | Soil EC | 40 cm |
Plot Delta (#23) | 61 | Temperature | 60 cm |
Plot Delta (#23) | 62 | Humidity | 60 cm |
Plot Delta (#23) | 94 | Soil EC | 60 cm |
Plot Delta (#23) | 63 | Temperature | 80 cm |
Plot Delta (#23) | 64 | Humidity | 80 cm |
Plot Delta (#23) | 95 | Soil EC | 80 cm |
Plot Delta (#23) | 65 | Temperature | 100 cm |
Plot Delta (#23) | 66 | Humidity | 100 cm |
Plot Delta (#23) | 96 | Soil EC | 100 cm |
Plot Delta (#23) | 67 | Nitrogen | 6.3 cm |
Plot Delta (#23) | 68 | Phosphorus | 6.3 cm |
Plot Delta (#23) | 69 | Potassium | 6.3 cm |
Endpoints
GET /api/plots
Retrieves a list of all plots and their associated sensors (without historical data). This is useful for getting an overview of the available sensors and their IDs.
Example Request (cURL):
curl -H "Authorization: Bearer YOUR_API_KEY" "https://agrometrix-492b7bf54e03.herokuapp.com/api/plots"
Example Request (JavaScript):
const apiKey = 'YOUR_API_KEY';
const url = 'https://agrometrix-492b7bf54e03.herokuapp.com/api/plots';
fetch(url, {
headers: {
'Authorization': `Bearer ${apiKey}`
}
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
Example Response:
{
"plots": [
{
"id": "plot_1",
"name": "Plot Alpha",
"location": "Tratamiento 15",
"sensors": [
{
"id": "1",
"type": "Temperature",
"unit": "°C",
"depth": 5,
"npk_set": null
},
// ... other sensors
]
},
// ... other plots
]
}
GET /api/readings
Fetches historical readings for one or more sensors within a specified date range.
Query Parameters:
sensor_ids
(required): A comma-separated string of sensor IDs.from
(optional): The start date of the range (format: YYYY-MM-DD). Defaults to the beginning of time if not provided.to
(optional): The end date of the range (format: YYYY-MM-DD). Defaults to the current date if not provided.
Example Request (cURL):
curl -H "Authorization: Bearer YOUR_API_KEY" "https://agrometrix-492b7bf54e03.herokuapp.com/api/readings?sensor_ids=1,2&from=2025-08-01&to=2025-08-15"
Example Request (JavaScript):
const apiKey = 'YOUR_API_KEY';
// Fetch readings for sensors 1 and 2 from Aug 1 to Aug 15, 2025
const url = 'https://agrometrix-492b7bf54e03.herokuapp.com/api/readings?sensor_ids=1,2&from=2025-08-01&to=2025-08-15';
fetch(url, {
headers: {
'Authorization': `Bearer ${apiKey}`
}
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
Example Response:
{
"readings": [
{
"sensor_id": "1",
"value": 17.5,
"time": "2025-08-01T14:30:00.000Z"
},
{
"sensor_id": "2",
"value": 45.2,
"time": "2025-08-01T14:30:00.000Z"
},
// ... other readings
]
}