curl
The GraphQL endpoint is called via POST requests with a JSON body. No
authentication is required.
Single query
curl -X POST https://data.bafu.admin.ch/api \
-H "Content-Type: application/json" \
--data '{"query":"{ water { observations { stations(where:{status:{_eq:\"Aufgebaut\"}}, limit: 5) { no name riverName } } } }"}'
The response follows the GraphQL specification: a successful call
contains a data object, a failed call an errors object.
Query from a file
Longer queries are kept in a file and submitted with --data-binary.
Line breaks and quoting are preserved.
cat > query.graphql <<'EOF'
{
water {
observations {
data_1day_mean(
where: {
station: { no: { _eq: "2009" } }
timestamp: { _gte: "2026-01-01T00:00:00Z", _lt: "2026-02-01T00:00:00Z" }
}
) {
timestamp
parameterName
value
unitSymbol
}
}
}
}
EOF
curl -X POST https://data.bafu.admin.ch/api \
-H "Content-Type: application/json" \
--data-binary "$(jq -Rs '{query: .}' < query.graphql)"
Query with variables
curl -X POST https://data.bafu.admin.ch/api \
-H "Content-Type: application/json" \
--data @- <<'EOF'
{
"query": "query DailyMean($from: AWSDateTime!, $to: AWSDateTime!, $station: String!) { water { observations { data_1day_mean(where: { station: { no: { _eq: $station } } timestamp: { _gte: $from, _lt: $to } }) { timestamp parameterName value unitSymbol } } } }",
"variables": {
"from": "2026-01-01T00:00:00Z",
"to": "2026-02-01T00:00:00Z",
"station": "2009"
}
}
EOF
Notes
- The header
Content-Type: application/jsonis required. - Double quotes inside the query string need escaping (
\") when passed via--data '…'. The escaping is not needed when the query is read from a file. - HTTP status is
200even for failed queries. Theerrorsfield in the response indicates problems.