API Tokens & REST API
URL: /tokens
The LEAF Portal exposes a REST API that allows external scripts, notebooks, and third-party tools to query sensor data programmatically. Access is authenticated with personal API tokens.

API Tokens
Section titled “API Tokens”Creating a token
Section titled “Creating a token”- Navigate to API Tokens in the sidebar.
- Click Generate token.
- Enter a descriptive name (e.g.
grafana,notebook). - Optionally set an expiry date.
- Click Create and copy the token — it is only shown once.
Managing tokens
Section titled “Managing tokens”Tokens can be revoked at any time by clicking the revoke button on the token row. Revoked tokens are immediately rejected by the API.
Using the API
Section titled “Using the API”Pass the token in the Authorization header:
curl -H "Authorization: Bearer <token>" https://your-portal/api/managementsOr as a query parameter:
curl "https://your-portal/api/data/recent?token=<token>&limit=20"Interactive API documentation (Swagger UI) is available at /api/docs.
Endpoints
Section titled “Endpoints”List access grants
Section titled “List access grants”GET /api/managementsReturns the list of managements (access grants) the token owner has access to.
[ { "id": "...", "organisation": "WUR", "department": "SSB", "entity": null, "time_start": null, "time_end": null }]Recent data
Section titled “Recent data”GET /api/data/recent?limit=50Returns the most recent sensor readings across all accessible departments.
Data by scope
Section titled “Data by scope”GET /api/data?organisation=WUR&department=SSB&metric=temperature&from=2024-01-01&limit=500Query parameters
Section titled “Query parameters”| Parameter | Description |
|---|---|
organisation | Organisation name |
department | Department name |
entity | Filter to a single entity (optional) |
metric | Filter to a single metric (optional) |
from | Start time, inclusive — ISO 8601 (optional) |
to | End time, exclusive — ISO 8601 (optional) |
limit | Max rows returned (default 1000, max 10000) |
Response format
Section titled “Response format”All data endpoints return a JSON array of objects:
[ { "time": "2024-06-01T10:00:00Z", "entity": "R1", "metric": "temperature", "value": 22.4, "tags": {"unit": "celsius"} }]Example: Python notebook
Section titled “Example: Python notebook”For a full interactive example using requests and pandas, see the API notebook (coming soon).