Ga naar inhoud

Python en andere clients

Elk systeem dat OAuth2 client credentials kan, kan os-meteo gebruiken.

Een token

curl -s https://<host>/wiwb1/token \
  -d grant_type=client_credentials -d client_id=<client_id> -d client_secret=<geheim>

Het antwoord heeft dezelfde vorm als dat van WIWB's Keycloak; access_token is een uur geldig. Het geheim mag ook als HTTP Basic mee (-u <client_id>:<geheim>).

Data

import requests

HOST = "https://<host>"
token = requests.post(
    f"{HOST}/wiwb1/token",
    data={"grant_type": "client_credentials", "client_id": "<client_id>", "client_secret": "<geheim>"},
).json()["access_token"]

body = {
    "Readers": [{
        "DataSourceCode": "Knmi.Synops",
        "Settings": {
            "Interval": {"Type": "Seconds", "Value": 3600},
            "StartDate": "20261129100000",
            "EndDate": "20261130100000",
            "VariableCodes": ["P"],
            "LocationCodes": ["06240"],
        },
    }],
    "Exporter": {"DataFormatCode": "hydronet.csv.simple", "Settings": {"DigitsToRound": 3}},
}
csv = requests.post(f"{HOST}/wiwb1/api/timeseries/get", json=body,
                    headers={"Authorization": f"Bearer {token}"}).text
curl -s https://<host>/wiwb1/api/timeseries/get \
  -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  -d '{"Readers":[{"DataSourceCode":"Knmi.Synops","Settings":{"Interval":{"Type":"Seconds","Value":3600},
       "StartDate":"20261129100000","EndDate":"20261130100000","VariableCodes":["P"],
       "LocationCodes":["06240"]}}],"Exporter":{"DataFormatCode":"hydronet.csv.simple"}}'

Het antwoord:

Date time,Location code,Variable code,Value,Quality,Availability,
2026-11-29 11:00:00,06240,RhRhRh,0.8,,1,
2026-11-29 12:00:00,06240,RhRhRh,0,,1,

De kolom Variable code noemt de variabele zoals de bron hem noemt (RhRhRh is de neerslag in een SYNOP-bericht), zoals WIWB dat ook doet. Zie de API voor de regels.

Uitproberen zonder code

De Swagger-pagina haalt zelf een token met Authorize en laat elke aanroep uitvoeren.