Congestion notifications
With the Congestion capability insights, an application can determine if the geographic area where the mobile device is located is going to experience congestion that might affect use cases such as bandwidth or latency. This way, the app might proactively move functionality to another area or use functionalities, such as QoD or Network Slicing to avoid congestion.
You can learn how to subscribe to Congestion notifications or unsubscribe from them below, so you can stay up to date with congestion levels for multiple devices.
TIP: Read more about the notification URL/auth token and how to create an HTTP server with a POST endpoint for congestion notifications.
Subscribing to Congestion notifications
With this snippet, you can subscribe to notifications for Congestion level changes and receive congestion updates. It passes the device information, subscription expiration time, notification URL, and notification authentication token as parameters. The method returns a subscription object. It also prints the ID of the subscription which you can use for management purposes.
import datetime
from network_as_code import NetworkAsCodeApi
# Create a client object as previously shown
client = NetworkAsCodeApi(
rapidapi_host="network-as-code.nokia.rapidapi.com",
api_key="<your-application-key-here>",
)
# Subscribe your device to Congestion notifications
congestion_subscription = client.congestion_insights.create_subscription(
device={"phone_number": "+999991234567"},
# Set a notification URL with auth token to receive updates
webhook={
"notification_url": "https://example.com/notifications",
"notification_auth_token": "my-secret-token",
},
# Set the duration of your subscription to congestion insights,
# e.g.: it can end in `n` days starting from now.
subscription_expire_time=datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(days=1),
)
# Subscriptions are identified by id, for management
# Use this to show the subscription:
print(congestion_subscription.subscription_id)
# Or check when your subscription starts/expires:
print(congestion_subscription.starts_at)
print(congestion_subscription.expires_at)NOTE: Learn how to get a list of subscriptions created for a device using this tutorial.
Congestion level notification handler
# congestion_handler.py
# run with: uvicorn congestion_handler:app
from fastapi import FastAPI, Header
from pydantic import BaseModel
from typing_extensions import Annotated
from typing import Union
app = FastAPI()
class Data(BaseModel):
level: str
class Notification(BaseModel):
id: str
source: str
type: str
specversion: str
datacontenttype: str
time: str
data: Data
@app.post("/notifications")
def receive_notification(
notification: Notification,
authorization: Annotated[Union[str, None], Header]
):
if authorization == "Bearer my-secret-token":
# We can now react to the notifications
# based on the Notification object
print(notification)Unsubscribing from congestion notifications
Finally, the code shows how to stop a subscription by calling the delete method.
# Use the resource_id from a previously created subscription
# and delete it to stop receiving notifications:
client.congestion_insights.delete_subscription(resource_id="<resource_id>")Congestion notifications parameters
| Parameters | Type | Description | Mandatory or Optional |
|---|---|---|---|
device | object | Information about the device for which congestion data is requested or subscribed to. | Mandatory |
subscription_expire_time | datetime | Expiration time for the congestion subscription as a datetime object | Mandatory |
notification_url | string | URL where notifications about congestion updates will be sent. | Mandatory |
notification_auth_token | string | Authentication token for accessing the notification URL. | Optional |
Last updated September 18, 2026