Docs › REST-API

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/metaVersionen, Aktionen, Standardwerte
GET/api/stationsLadepunkte mit Live-Zustand
POST/api/stationsanlegen
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}/messagesProtokoll, ?after=<id>&limit=
GET/api/stations/{id}/transactionsLadevorgänge
GET / POST/api/cposCPOs 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-aneues Token A, Verbindung zurücksetzen
POST/api/cpos/{id}/registerHandshake 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}/tokensvom eMSP gepushte Ladekarten
GET/api/cpos/{id}/sessionsSessions
GET/api/cpos/{id}/logOCPI-Protokoll
GET / POST / DELETE/api/keysAPI-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.

REST API

Everything the UI does is available via REST – ideal for automated tests of your backend in CI: create charge points, run a charging session, then check the log for schema violations.

Authentication

Create an API key under Account & API (starts with cs_, shown only once). Send it as X-API-Key: cs_… or Authorization: Bearer cs_…. A key acts for your whole team.

Examples

export OS=https://ocpp-sim.dev
export KEY=cs_…   # API key from “Account & API”

# List charge points
curl -H "X-API-Key: $KEY" $OS/api/stations

# Create a charge point (connects immediately; note the returned id as $ID)
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}
}'

# Charge on connector 1 and stop again
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

# Send a custom message to your backend
curl -H "X-API-Key: $KEY" -X POST $OS/api/stations/$ID/send \
     -H "Content-Type: application/json" \
     -d '{"action": "DataTransfer", "payload": {"vendorId": "test"}}'

# Read the log (newest last)
curl -H "X-API-Key: $KEY" "$OS/api/stations/$ID/messages?after=0&limit=200"

# Create an OCPI CPO with demo data, then switch on fault injection
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}}'

Endpoints

GET/api/metaVersions, actions, defaults
GET/api/stationsCharge points with live status
POST/api/stationscreate
GET / PATCH / DELETE/api/stations/{id}read / update (restarts) / delete
POST/api/stations/{id}/power{"action": "connect" | "disconnect" | "reboot"}
POST/api/stations/{id}/connectors/{n}/{action}plug, unplug, swipe, charge, stop, fault, repair; optional body {"id_tag": …, "ev": {…}}
POST/api/stations/{id}/send{"action", "payload", "validate"} or {"raw": "…"}
GET/api/stations/{id}/messagesLog, ?after=<id>&limit=
GET/api/stations/{id}/transactionsTransactions
GET / POST/api/cposList / create CPOs ("demo": true for demo data)
GET / PATCH / DELETE/api/cpos/{id}read / update (name, strict, insecure_tls, faults) / delete
POST/api/cpos/{id}/token-anew token A, reset connection
POST/api/cpos/{id}/registerstart handshake with eMSP {"versions_url", "token"}
POST / PATCH / DELETE/api/cpos/{id}/locations[/{lid}]Locations
POST / PATCH / DELETE/api/cpos/{id}/tariffs[/{tid}]Tariffs (with "elements" for time-of-use)
GET/api/cpos/{id}/tokensCharging cards pushed by the eMSP
GET/api/cpos/{id}/sessionsSessions
GET/api/cpos/{id}/logOCPI log
GET / POST / DELETE/api/keysAPI keys

Complete, machine-readable reference: OpenAPI / Swagger. Errors come as HTTP 4xx with {"detail": …}; schema violations of send as {"detail": {"schema_errors": […]}}.

Tip for CI

Poll /api/stations/{id}/messages?after=<last id> and fail the test if an entry has a non-empty errors field – that means a message from your backend violated the OCPP schema.

Fehlt etwas oder ist etwas unklar? Fragen Sie im Forum.