Device Swap
Network as Code provides identity and security capabilities that allow your applications to prevent or proactively react to fraud by using resources that go beyond traditional 2FA authentication processes. The Device Swap feature performs real-time checks on the last Device Swap event, providing real-time information about whether the SIM card associated with a user's phone number has been transferred to a different physical device. Device Swap information can be invaluable for enhancing security, fraud detection, and ensuring compliance with regulatory requirements in various applications.
What does this feature do?
-
It tells when the last Device Swap occurred
If no swap has been performed, it can return a null value or the first time that the SIM was installed in a device (the timestamp of the first time that the phone number was connected to the network).
-
Allows you to check if a device was swapped recently with a specific time span that you can define. So, you can answer the question: Has the event occurred within the last
nhours?If the phone number has never been installed in a device or no data is available, returns
422error.
Terminology and acronyms
- Device Swap: A Device Swap is a process in which the association between a user's mobile phone number
(
MSISDN) and a device (IMEI) is created for the first time or changes for any reasons.
What's behind this technology?
The Device Swap functionality follows CAMARA definitions, which is an open-source project within Linux foundation. Network as Code bridges the gap between your application and the Operator platform making the connection seamless so you can retrieve Device swap data. After you register on Network as Code Developer Portal and get consent & authorization for devices, you will be able to easily use and integrate this API into your applications.
Device Swap SDK
Retrieving latest Device Swap date
With the Device Swap SDK, you can easily retrieve the last date in which the device of the end-user was swapped.
import network_as_code as nac
from network_as_code.models.device import Device
# Initialize the client object with your application key
client = nac.NetworkAsCodeClient(
token="<your-application-key-here>"
)
# Then, create a device object for the phone number you want to check
my_device = client.devices.get(
# The phone number does not accept spaces or parentheses
phone_number="+99999991000"
)
# The date of the last device swap can be retrieved like so:
device_swap_date = my_device.get_device_swap_date()
# Otherwise it behaves like a regular datetime object
print(f"Last device swap (or SIM installation) happened on {device_swap_date.isoformat()}")Get Device Swap date responses
| Response | Type | Description |
|---|---|---|
2025-06-19 09:51:44.271000+00:00 | string | The latest date for when a device swap has occurred. If no device swap has occured the response can be the SIM installation date. |
None | NoneType | If no device swap has occurred, the response can be None. |
Checking Device Swap occurrence
If you want to verify if a device was swapped within the default time period of 240 hours, you can do this with the verify device swap method with no parameters passed.
if my_device.verify_device_swap():
print("A device swap has occurred!")Also, in case you suspect a device swap attempt occurred in the last n hours,
you can pass this value as a parameter to the verify device swap method,
and precisely check if the SIM of the end-user has been installed in a different device during this period.
if my_device.verify_device_swap(max_age=1):
print("A device swap has occurred within the past hour!")Verify Device Swap parameters
| Parameter | Type | Description | Mandatory or Optional |
|---|---|---|---|
max_age | integer | Time amount in hours, from one hour up to 2400. Can be added as a parameter to the verify device swap method to check if a device swap has occurred within the last n hours. For example .verify_device_swap(max_age=2) | Optional |
Verify Device Swap responses
| Response | Type | Description |
|---|---|---|
True | boolean | Indicates, that a device swap has occurred. If a max age parameter of n hours was given, indicates that a device swap occurred within the last n hours. |
False | boolean | Indicates, that a device swap has not occurred. If a max age parameter of n hours was given, indicates that a device swap has not occurred within the last n hours. |
Simulated Device Swap scenario responses
The Network as Code simulators have been configured to provide specific Device Swap results for specific simulated devices based on their device identifier. This will be helpful in testing your code against the different responses, including possible errors, by simply substituting the device identifier in your code.
The device identifiers and their responses can be found in the following table:
| Device identifier type | Device identifier | HTTP status code | HTTP status code description | Response description |
|---|---|---|---|---|
| Phone Number | +99999991000 | 200 | Success | Device swap has occurred |
| Phone Number | +99999991001 | 200 | Success | Device swap has not occurred |
Last updated November 05, 2025