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.
from network_as_code import NetworkAsCodeApi
from datetime import datetime, timezone, timedelta
# Create a client object
client = NetworkAsCodeApi(
api_key="<your-application-key-here>",
rapidapi_host="network-as-code.nokia.rapidapi.com"
)
# Subscribe your device to Congestion notifications
congestion_subscription = client.congestion_insights.create_subscription(
device={"phone_number": "+36719991000"},
# 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.now(timezone.utc) + timedelta(days=1)
)
# Get a list of congestion subscriptions
subscriptions = client.congestion_insights.list_subscriptions()
# Get only the first or one subscription at a time by its index
first_subscription = client.congestion_insights.list_subscriptions()[0]
# Get a subscription previously created by its ID
one_subscription = client.congestion_insights.get_subscription(
congestion_subscription.resource_id
)Congestion subscription response parameters
| Parameters | Type | Description |
|---|---|---|
subscription_id | string | It represents the subscription identifier. |
startedAt | datetime | Timezone-aware timestamp which represents when this subscription started. |
expiresAt | datetime | Timezone-aware timestamp which represents when this subscription should expire. |
Last updated September 18, 2026