Query records of an Opendatasoft dataset
query_portal_recordsFetch and filter records from Swiss Opendatasoft portals using ODSQL, including field selection, grouping, sorting, paging, and radius searches around coordinates.
Instructions
Fetch records from a dataset on a Swiss Opendatasoft portal with ODSQL: where (e.g. "kanton = 'BS'", "jahr >= 2020", "search(name, 'Bahnhof')"), select (e.g. 'bahnhof_haltestelle, dtv, jahr'), order_by (e.g. 'dtv desc'), group_by with aggregates (select 'kanton, count(*) as n, sum(dtv) as total', group_by 'kanton'), limit/offset. Convenience near {lat, lon, radius_m} finds the dataset's geo_point_2d field and returns only records within the radius, sorted by distance (e.g. parking garages within 800 m of Basel SBB: portal 'basel-stadt', near {lat:47.5476, lon:7.5896, radius_m:800}). Real-time datasets (parking occupancy, SBB data) are cached only 10 min. Get field names first with get_portal_dataset.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"portal": "<portal>",
"dataset_id": "<dataset_id>"
},
"name": "query_portal_records"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| lang | No | Language for localized values where the portal supports it | |
| near | No | Radius search around a WGS84 point, e.g. {lat: 47.5476, lon: 7.5896, radius_m: 500} | |
| limit | No | Records to return (max 100) | |
| where | No | ODSQL filter, e.g. "jahr = 2023 AND dtv > 10000" (string literals in single or double quotes) | |
| offset | No | Paging offset (offset + limit ≤ 10000) | |
| portal | Yes | Portal id, alias or domain: 'sbb' (data.sbb.ch), 'basel-stadt' (data.bs.ch), 'basel-landschaft' (data.bl.ch), 'st-gallen' (daten.sg.ch), 'stadt-st-gallen' (daten.stadt.sg.ch), 'graubuenden' (data.gr.ch), 'thurgau' (data.tg.ch); any other '<tenant>.opendatasoft.com' host also works | |
| select | No | Fields/expressions to return, e.g. 'name, belegung, geo_point_2d' or 'kanton, count(*) as n' | |
| group_by | No | e.g. 'kanton' or 'year(datum)'; combine with aggregates in select | |
| order_by | No | e.g. 'dtv desc' or 'n desc' | |
| geo_field | No | geo_point_2d field to use for `near` (auto-detected if omitted) | |
| dataset_id | Yes | Dataset id from search_portal_datasets |