Getting a Device-Status subscription

Here, we will show how to get a subscription using multiple methods. If you previously created a subscription and you need to modify or delete it, you can easily retrieve it by its ID.

You can also get a single active subscription or a list of them, check the connectivity or roaming status of devices. The connectivity status polling method returns whether a device is connected to a network or not. Now, besides returning if a device is roaming or not, the roaming status polling method shows the current country code and name.

import network_as_code as nac
 
from network_as_code.models.device import Device, DeviceIpv4Addr
 
# Create the client and device objects
client = nac.NetworkAsCodeClient(...)
 
my_device = client.devices.get(...)
 
# Create a subscription
connectivity_subscription = client.connectivity.subscribe(...)
 
# Get a subscription by its ID
subscription = client.connectivity.get_subscription(connectivity_subscription.id)
 
# Retrieve list of active Device Status subscriptions
subscriptions = client.connectivity.get_subscriptions()
 
# Check the connectivity or roaming status of subscriptions
connectivity_status = my_device.get_connectivity()
 
roaming_status = my_device.get_roaming()

Note that the snippet above assumes you have already created Device Status subscription before, which you can learn how to do here. And that you have also created a Network-as-Code client and identified your mobile network device previously.

Last updated on July 09, 2024

On this page