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.
Learn more about the notification URL/auth token and how to create an HTTP server with a POST endpoint for roaming notifications.
Roaming notification handler
# status_handler.py
# run with: uvicorn status_handler:app
from fastapi import FastAPI, Header
from pydantic import BaseModel
from typing_extensions import Annotated
from typing import List, 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[str] | 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
@app.post("/notifications")
def receive_notification(
notification: RoamingStatusNotification,
authorization: Annotated[Union[str, None], Header]
):
if authorization == "Bearer my-token":
# We can now react to the notifications
# based on the Notification object
print(notification)
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.