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
PlotSensor IDSensor TypeDepth
Plot Alpha (#1)1Temperature5 cm
Plot Alpha (#1)2Humidity5 cm
Plot Alpha (#1)73Soil EC5 cm
Plot Alpha (#1)3Temperature20 cm
Plot Alpha (#1)4Humidity20 cm
Plot Alpha (#1)74Soil EC20 cm
Plot Alpha (#1)5Temperature40 cm
Plot Alpha (#1)6Humidity40 cm
Plot Alpha (#1)75Soil EC40 cm
Plot Alpha (#1)7Temperature60 cm
Plot Alpha (#1)8Humidity60 cm
Plot Alpha (#1)76Soil EC60 cm
Plot Alpha (#1)9Temperature80 cm
Plot Alpha (#1)10Humidity80 cm
Plot Alpha (#1)77Soil EC80 cm
Plot Alpha (#1)11Temperature100 cm
Plot Alpha (#1)12Humidity100 cm
Plot Alpha (#1)78Soil EC100 cm
Plot Alpha (#1)13Nitrogen6.3 cm
Plot Alpha (#1)14Phosphorus6.3 cm
Plot Alpha (#1)15Potassium6.3 cm
Plot Beta (#44)19Temperature5 cm
Plot Beta (#44)20Humidity5 cm
Plot Beta (#44)79Soil EC5 cm
Plot Beta (#44)21Temperature20 cm
Plot Beta (#44)22Humidity20 cm
Plot Beta (#44)80Soil EC20 cm
Plot Beta (#44)23Temperature40 cm
Plot Beta (#44)24Humidity40 cm
Plot Beta (#44)81Soil EC40 cm
Plot Beta (#44)25Temperature60 cm
Plot Beta (#44)26Humidity60 cm
Plot Beta (#44)82Soil EC60 cm
Plot Beta (#44)27Temperature80 cm
Plot Beta (#44)28Humidity80 cm
Plot Beta (#44)83Soil EC80 cm
Plot Beta (#44)29Temperature100 cm
Plot Beta (#44)30Humidity100 cm
Plot Beta (#44)84Soil EC100 cm
Plot Beta (#44)31Nitrogen6.3 cm
Plot Beta (#44)32Phosphorus6.3 cm
Plot Beta (#44)33Potassium6.3 cm
Plot Gamma (#52)37Temperature5 cm
Plot Gamma (#52)38Humidity5 cm
Plot Gamma (#52)85Soil EC5 cm
Plot Gamma (#52)39Temperature20 cm
Plot Gamma (#52)40Humidity20 cm
Plot Gamma (#52)86Soil EC20 cm
Plot Gamma (#52)41Temperature40 cm
Plot Gamma (#52)42Humidity40 cm
Plot Gamma (#52)87Soil EC40 cm
Plot Gamma (#52)43Temperature60 cm
Plot Gamma (#52)44Humidity60 cm
Plot Gamma (#52)88Soil EC60 cm
Plot Gamma (#52)45Temperature80 cm
Plot Gamma (#52)46Humidity80 cm
Plot Gamma (#52)89Soil EC80 cm
Plot Gamma (#52)47Temperature100 cm
Plot Gamma (#52)48Humidity100 cm
Plot Gamma (#52)90Soil EC100 cm
Plot Gamma (#52)49Nitrogen6.3 cm
Plot Gamma (#52)50Phosphorus6.3 cm
Plot Gamma (#52)51Potassium6.3 cm
Plot Delta (#23)55Temperature5 cm
Plot Delta (#23)56Humidity5 cm
Plot Delta (#23)91Soil EC5 cm
Plot Delta (#23)57Temperature20 cm
Plot Delta (#23)58Humidity20 cm
Plot Delta (#23)92Soil EC20 cm
Plot Delta (#23)59Temperature40 cm
Plot Delta (#23)60Humidity40 cm
Plot Delta (#23)93Soil EC40 cm
Plot Delta (#23)61Temperature60 cm
Plot Delta (#23)62Humidity60 cm
Plot Delta (#23)94Soil EC60 cm
Plot Delta (#23)63Temperature80 cm
Plot Delta (#23)64Humidity80 cm
Plot Delta (#23)95Soil EC80 cm
Plot Delta (#23)65Temperature100 cm
Plot Delta (#23)66Humidity100 cm
Plot Delta (#23)96Soil EC100 cm
Plot Delta (#23)67Nitrogen6.3 cm
Plot Delta (#23)68Phosphorus6.3 cm
Plot Delta (#23)69Potassium6.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
  ]
}