Roaming notifications

The roaming feature allows querying and reporting information on device roaming status, so you can monitor when it's roaming or not.

Getting roaming notifications

The code snippet below will set up an HTTP server with a POST endpoint. This will allow receiving device roaming status updates. For example, you can learn if a device if a device is roaming or not. Below, we'll set up a notification handler, so you can react based on status notifications.

Roaming notification handler

# run with: uvicorn status_handler:app
from fastapi import FastAPI, Header
from pydantic import BaseModel
from typing_extensions import Annotated
from typing import Union
app = FastAPI()
class Device(BaseModel):
    phoneNumber: str | None
    networkAccessIdentifier: str | None
    ipv4Address: str | None
    ipv6Address: str | None
class RoamingEventDetail(BaseModel):
    device: Device
    subscriptionId: str
    roaming: bool | None
    countryCode: int | None
    countryName: List[String] | None
    terminationReason: str
class Event(BaseModel):
    eventTime: str
    eventDetail: RoamingEventDetail
class Data(BaseModel):
    device: Device
    subscriptionId: str
    roaming: RoamingEventDetail
class RoamingStatusNotification(BaseModel):
    id: str
    source: str
    type: str
    specversion: str
    datacontenttype: str
    time: str
    eventSubscriptionId: str
    event: Event
    data: Data"/notifications")
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

What is a notification URL?

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

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 May 23, 2024