Skip to content

Push Notifications

Learn how to implement push notifications between OCPI parties.

Overview

OCPI push notifications allow parties to notify each other about changes to OCPI objects (locations, sessions, CDRs, etc.).

Implementation

push

Classes

Functions:

client_url

client_url(module_id, object_id, base_url, object_data=None)

Receiver URL for a pushed object.

The path segments name the party that owns the object, so they come from the object itself: a CPO may publish under several parties, and a receiver rejects a path party that differs from the body (elu-charge#1607). The configured party is only the fallback for objects that carry none.

Source code in ocpi/core/push.py
def client_url(
    module_id: ModuleID,
    object_id: str,
    base_url: str,
    object_data: dict | None = None,
) -> str:
    """Receiver URL for a pushed object.

    The path segments name the party that owns the object, so they come from
    the object itself: a CPO may publish under several parties, and a receiver
    rejects a path party that differs from the body (elu-charge#1607). The
    configured party is only the fallback for objects that carry none.
    """
    if module_id == ModuleID.cdrs:
        return base_url
    data = object_data or {}
    country_code = data.get("country_code") or settings.COUNTRY_CODE
    party_id = data.get("party_id") or settings.PARTY_ID
    base = base_url.rstrip("/")
    return f"{base}/{country_code}/{party_id}/{object_id}"

HTTP Push

HTTP push notifications are sent via POST requests to the receiving party's push endpoint.

WebSocket Push

WebSocket push notifications provide real-time bidirectional communication.

Note

WebSocket push is experimental and may not be supported by all OCPI implementations.