REST-API
Alles, was die Oberfläche kann, geht auch per REST – ideal für automatische Tests Ihres Backends in CI: Ladepunkte anlegen, einen Ladevorgang durchspielen, danach das Protokoll auf Schemaverstöße prüfen.
Anmeldung
Unter Konto & API einen API-Schlüssel erzeugen (beginnt mit cs_, wird nur einmal
angezeigt). Mitschicken als X-API-Key: cs_… oder Authorization: Bearer cs_…. Ein Schlüssel
handelt für das ganze Team.
Beispiele
export OS=https://ocpp-sim.dev
export KEY=cs_… # API-Schlüssel aus „Konto & API“
# Ladepunkte auflisten
curl -H "X-API-Key: $KEY" $OS/api/stations
# Ladepunkt anlegen (verbindet sich sofort; die zurückgegebene id als $ID merken)
curl -H "X-API-Key: $KEY" -H "Content-Type: application/json" -X POST $OS/api/stations -d '{
"ident": "CP001", "ocpp_version": "2.0.1",
"csms_url": "wss://csms.example.com/ocpp", "password": "geheim",
"connectors": 2, "power_type": "AC", "max_power_kw": 22,
"options": {"speed": 10}
}'
# An Anschluss 1 laden und wieder stoppen
curl -H "X-API-Key: $KEY" -X POST $OS/api/stations/$ID/connectors/1/charge \
-H "Content-Type: application/json" -d '{"id_tag": "TESTCARD1"}'
curl -H "X-API-Key: $KEY" -X POST $OS/api/stations/$ID/connectors/1/stop
# Eigene Nachricht an Ihr Backend senden
curl -H "X-API-Key: $KEY" -X POST $OS/api/stations/$ID/send \
-H "Content-Type: application/json" \
-d '{"action": "DataTransfer", "payload": {"vendorId": "test"}}'
# Protokoll lesen (neueste zuletzt)
curl -H "X-API-Key: $KEY" "$OS/api/stations/$ID/messages?after=0&limit=200"
# OCPI-CPO mit Demo-Daten anlegen, dann Fehlerinjektion einschalten
curl -H "X-API-Key: $KEY" -H "Content-Type: application/json" -X POST $OS/api/cpos \
-d '{"name": "Test-CPO", "country_code": "DE", "party_id": "TST", "demo": true}'
curl -H "X-API-Key: $KEY" -H "Content-Type: application/json" -X PATCH $OS/api/cpos/$CPO \
-d '{"faults": {"cdr": "duplicate", "error_rate": 0.1, "error_code": 3000}}'
Endpunkte
GET | /api/meta | Versionen, Aktionen, Standardwerte |
GET | /api/stations | Ladepunkte mit Live-Zustand |
POST | /api/stations | anlegen |
GET / PATCH / DELETE | /api/stations/{id} | lesen / ändern (Neustart) / löschen |
POST | /api/stations/{id}/power | {"action": "connect" | "disconnect" | "reboot"} |
POST | /api/stations/{id}/connectors/{n}/{action} | plug, unplug, swipe, charge, stop, fault, repair; Body optional {"id_tag": …, "ev": {…}} |
POST | /api/stations/{id}/send | {"action", "payload", "validate"} oder {"raw": "…"} |
GET | /api/stations/{id}/messages | Protokoll, ?after=<id>&limit= |
GET | /api/stations/{id}/transactions | Ladevorgänge |
GET / POST | /api/cpos | CPOs auflisten / anlegen ("demo": true für Demo-Daten) |
GET / PATCH / DELETE | /api/cpos/{id} | lesen / ändern (name, strict, insecure_tls, faults) / löschen |
POST | /api/cpos/{id}/token-a | neues Token A, Verbindung zurücksetzen |
POST | /api/cpos/{id}/register | Handshake beim eMSP starten {"versions_url", "token"} |
POST / PATCH / DELETE | /api/cpos/{id}/locations[/{lid}] | Standorte |
POST / PATCH / DELETE | /api/cpos/{id}/tariffs[/{tid}] | Tarife (mit "elements" für Zeittarife) |
GET | /api/cpos/{id}/tokens | vom eMSP gepushte Ladekarten |
GET | /api/cpos/{id}/sessions | Sessions |
GET | /api/cpos/{id}/log | OCPI-Protokoll |
GET / POST / DELETE | /api/keys | API-Schlüssel |
Vollständige, maschinenlesbare Referenz: OpenAPI / Swagger. Fehler kommen als HTTP 4xx mit
{"detail": …}, Schemaverstöße bei send als {"detail": {"schema_errors": […]}}.
Tipp für CI
/api/stations/{id}/messages?after=<letzte id> abfragen und den Test scheitern lassen, wenn ein Eintrag
ein nicht leeres Feld errors hat – dann hat eine Nachricht Ihres Backends das OCPP-Schema verletzt.