Vonage Network Sim Swap Client

1.1.2 · active · verified Thu Apr 16

This package provides access to the Vonage Sim Swap Network API, primarily acting as a dependency installer for the main `vonage` Python SDK (currently v4.7.2). It enables developers to check for recent SIM card swaps for a given phone number, which is crucial for fraud detection and enhancing security. While `vonage-network-sim-swap` itself is at version 1.1.2, the core Sim Swap functionality is integrated and accessed through the `vonage.Client().sim_swap` object provided by the `vonage` library. It follows the release cadence of the main `vonage` SDK for Sim Swap related updates.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the Vonage client and use the `check_sim_swap_date` method to query for SIM swap activity on a given phone number. Ensure your Vonage API Key and Secret are configured, and the phone number is in E.164 format. You must also enable the Network Registry capability in your Vonage Application for this API to work.

import vonage
import os
from datetime import date

# Ensure VONAGE_API_KEY and VONAGE_API_SECRET are set in your environment
# or replace with actual credentials for testing (not recommended for production)
api_key = os.environ.get('VONAGE_API_KEY', 'YOUR_API_KEY')
api_secret = os.environ.get('VONAGE_API_SECRET', 'YOUR_API_SECRET')
phone_number = os.environ.get('VONAGE_SIM_SWAP_PHONE_NUMBER', '+15551234567')

if not api_key or not api_secret or api_key == 'YOUR_API_KEY':
    print("Please set VONAGE_API_KEY and VONAGE_API_SECRET environment variables.")
    exit(1)

if not phone_number.startswith('+'):
    print("Warning: Phone number should be in E.164 format (e.g., +15551234567). Prepending '+' for example.")
    phone_number = '+' + phone_number

client = vonage.Client(key=api_key, secret=api_secret)

try:
    # Check for SIM swap activity as of a specific date
    # The date should be within the last 30 days for most carriers.
    response = client.sim_swap.check_sim_swap_date(
        phone_number=phone_number,
        date_identifier=date(2024, 1, 1), # Example date. Use a relevant date for real checks.
        five_g_nr_check=False # Optional: set to True for 5G network checks if supported and desired
    )

    if response.is_successful():
        print(f"SIM Swap Check successful for {phone_number}:")
        print(f"  Status: {response.status}")
        print(f"  Latest SIM Swap Date: {response.latest_sim_swap_date}")
        print(f"  Is Swapped: {response.is_swapped}")
    else:
        print(f"SIM Swap Check failed for {phone_number}:")
        print(f"  Error Code: {response.error_code}")
        print(f"  Error Message: {response.error_message}")
except Exception as e:
    print(f"An unexpected error occurred: {e}")

view raw JSON →