Session notifications

Creating a session with a notification URL

You can optionally configure a notification (webhook) URL to receive QoD session updates. This way, you or your client can be notified of important session events, such as creation, deletion, etc.

import network_as_code as nac
from network_as_code.models.device import Device, DeviceIpv4Addr
# Begin by creating a client for Network as Code:
client = nac.NetworkAsCodeClient(
# Then, create a device object.
# Remember to assign its Device ID and current IP address(es):
my_device = client.devices.get(
    ipv4_address = DeviceIpv4Addr(
    ipv6_address = "2001:db8:1234:5678:9abc:def0:fedc:ba98",
    # The phone number accepts the "+" sign, but not spaces or "()" marks
    phone_number = "36721601234567"
# Create a QoD session with QOS_L (large bandwidth)
# and get notifications
my_session = my_device.create_qod_session(
    # Use HTTPS to send notifications
# Show a list of all the QoD sessions associated with a device

Setting up a web server

The code snippet below will set up an HTTP server with a POST endpoint, so you can get session-event updates:

import time
from fastapi import FastAPI, Header
from pydantic import BaseModel
from typing_extensions import Annotated
from typing import Union
# Our web server for receiving QoD notifications
app = FastAPI()
class EventDetail(BaseModel):
    sessionId: str
    qosStatus: str
    statusInfo: str
class Event(BaseModel):
    eventType: str
    eventTime: str
    eventDetail: EventDetail
class Notification(BaseModel):
    id: str
    source: str
    type: str
    specversion: str
    datacontenttype: str
    time: str
    event: Event
    data: EventDetail"/qod")
def receive_notification(
    notification: Notification,
    authorization: Annotated[Union[str, None], Header]
    if authorization == "Bearer my-token":
        # We can now react to the notifications
        # based on the Notification object

Device object parameters

The snippet above identified a mobile network device in multiple ways (IP addresses, port, etc). Learn how to create a device object and understand how the DeviceIPv4Addr model works using NAT technology.

Session notification parameters

The Session object is created with a specific duration, representing a new session for the device. The following parameters can be passed to this method:

profileThe QoS profile that indicates the connection type to be prioritized between two points.
service_ipv4The service identified by the application IPv4 address (optional).
service_ipv6The service identified by the application IPv6 address (optional).
notification_urlThe recipient's HTTP endpoint, which is a web server configured to receive POST requests.
notification_auth_tokenThe password used to identify the sender of the notification.

What is a notification URL?

Learn more about the notification URL/auth token and how to create a web server for them.

Last updated on May 23, 2024