Getting Congestion subscriptions

Here, we will show how to get congestion subscriptions using multiple methods. If you previously created a congestion subscription and you need to modify or delete it, you can easily retrieve it by its ID or index. You can do so by using the following examples:

NOTE: Subscribe to Congestion notifications before polling congestion levels or getting subscription information. The subscription is a mandatory step and must be completed first. This way you can ensure you'll be able to use all the other Congestion functionalities.

import network_as_code as nac

from datetime import datetime, timezone, timedelta

from network_as_code.models.device import DeviceIpv4Addr

# Create a client and device objects as previously shown
client = nac.NetworkAsCodeClient(
    token="<your-application-key-here>"
)

my_device = client.devices.get(
    "[email protected]",
    ipv4_address=DeviceIpv4Addr(
        public_address="192.0.2.3",
        private_address="192.0.2.204",
        public_port=80
    ),
)

# Subscribe your device to Congestion notifications
congestion_subscription = client.insights.subscribe_to_congestion_info(
    my_device,
    # Set the duration of your subscription to congestion insights,
    # e.g.: it can end in `n` days starting from now.
    subscription_expire_time=datetime.now(timezone.utc) + timedelta(days=1),
    # Set a notification URL with auth token to receive updates
    notification_url="https://example.com/notify",
    notification_auth_token="my-secret-token"
)

# Get a list of congestion subscriptions
subscriptions = client.insights.get_congestion_subscriptions()

# Get only the first or one subscription at a time by its index
first_subscription = client.insights.get_congestion_subscriptions()[0]

# Get a subscription previously created by its ID
one_subscription = client.insights.get_congestion_subscription(
    congestion_subscription.id
)

Congestion subscription response parametersheader link

ParametersTypeDescription
idstringIt represents the subscription identifier.
starts_atdatetimeTimezone-aware timestamp which represents when this subscription started.
expires_atdatetimeTimezone-aware timestamp which represents when this subscription should expire.

Last updated November 05, 2025