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?

  1. 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).

  2. 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 n hours?

    If the phone number has never been installed in a device or no data is available, returns 422 error.

Terminology and acronymsheader link

What's behind this technology?header link

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 SDKheader link

Retrieving latest Device Swap dateheader link

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 responsesheader link

ResponseTypeDescription
2025-06-19 09:51:44.271000+00:00stringThe latest date for when a device swap has occurred. If no device swap has occured the response can be the SIM installation date.
NoneNoneTypeIf no device swap has occurred, the response can be None.

Checking Device Swap occurrenceheader link

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 parametersheader link

ParameterTypeDescriptionMandatory or Optional
max_ageintegerTime 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 responsesheader link

ResponseTypeDescription
TruebooleanIndicates, 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.
FalsebooleanIndicates, 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 responsesheader link

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 typeDevice identifierHTTP status codeHTTP status code descriptionResponse description
Phone Number+99999991000200SuccessDevice swap has occurred
Phone Number+99999991001200SuccessDevice swap has not occurred

Last updated November 05, 2025