{"id":9396,"library":"vonage-network-sim-swap","title":"Vonage Network Sim Swap Client","description":"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.","status":"active","version":"1.1.2","language":"en","source_language":"en","source_url":"https://github.com/Vonage/vonage-python-sdk","tags":["vonage","sim swap","network API","telecom","fraud detection","security"],"install":[{"cmd":"pip install vonage-network-sim-swap","lang":"bash","label":"Install `vonage-network-sim-swap` (also installs `vonage`)"}],"dependencies":[{"reason":"Provides the core client and Sim Swap functionality, as this package acts as a dependency wrapper.","package":"vonage","optional":false}],"imports":[{"note":"The `vonage-network-sim-swap` package installs the `vonage` library as a dependency. Sim Swap API access is provided via methods on `vonage.Client().sim_swap`.","symbol":"Client","correct":"import vonage"},{"note":"Required for specifying the date parameter in methods like `check_sim_swap_date`.","symbol":"date","correct":"from datetime import date"}],"quickstart":{"code":"import vonage\nimport os\nfrom datetime import date\n\n# Ensure VONAGE_API_KEY and VONAGE_API_SECRET are set in your environment\n# or replace with actual credentials for testing (not recommended for production)\napi_key = os.environ.get('VONAGE_API_KEY', 'YOUR_API_KEY')\napi_secret = os.environ.get('VONAGE_API_SECRET', 'YOUR_API_SECRET')\nphone_number = os.environ.get('VONAGE_SIM_SWAP_PHONE_NUMBER', '+15551234567')\n\nif not api_key or not api_secret or api_key == 'YOUR_API_KEY':\n    print(\"Please set VONAGE_API_KEY and VONAGE_API_SECRET environment variables.\")\n    exit(1)\n\nif not phone_number.startswith('+'):\n    print(\"Warning: Phone number should be in E.164 format (e.g., +15551234567). Prepending '+' for example.\")\n    phone_number = '+' + phone_number\n\nclient = vonage.Client(key=api_key, secret=api_secret)\n\ntry:\n    # Check for SIM swap activity as of a specific date\n    # The date should be within the last 30 days for most carriers.\n    response = client.sim_swap.check_sim_swap_date(\n        phone_number=phone_number,\n        date_identifier=date(2024, 1, 1), # Example date. Use a relevant date for real checks.\n        five_g_nr_check=False # Optional: set to True for 5G network checks if supported and desired\n    )\n\n    if response.is_successful():\n        print(f\"SIM Swap Check successful for {phone_number}:\")\n        print(f\"  Status: {response.status}\")\n        print(f\"  Latest SIM Swap Date: {response.latest_sim_swap_date}\")\n        print(f\"  Is Swapped: {response.is_swapped}\")\n    else:\n        print(f\"SIM Swap Check failed for {phone_number}:\")\n        print(f\"  Error Code: {response.error_code}\")\n        print(f\"  Error Message: {response.error_message}\")\nexcept Exception as e:\n    print(f\"An unexpected error occurred: {e}\")\n","lang":"python","description":"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."},"warnings":[{"fix":"Update your code to use `client.sim_swap.check_sim_swap_date()` or `client.sim_swap.check_sim_swap_two_factor()` as per the latest Vonage Python SDK documentation.","message":"Older versions of the Vonage SDK or Sim Swap examples might refer to a `check_sim_swap()` method, which is now deprecated. Use `check_sim_swap_date()` or `check_sim_swap_two_factor()` instead for current functionality.","severity":"breaking","affected_versions":"<4.x.x (for main `vonage` SDK), <1.x.x (for this package's conceptual use)"},{"fix":"Always ensure phone numbers are properly formatted to E.164 before making API calls. You can validate and format numbers using libraries like `phonenumbers`.","message":"The Vonage Sim Swap API requires phone numbers to be in E.164 format (e.g., `+12345678900`), including the country code prefix. Incorrect formatting will lead to API errors.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Go to your Vonage Dashboard -> Applications, select or create an application, and enable the 'Network Registry' capability. For local development, configure 'Playground' access.","message":"To use the Sim Swap API, you must enable the 'Network Registry' capability within your Vonage Application in the Vonage Dashboard. For initial testing, utilize the 'Playground' mode, which allows testing with virtual operators or whitelisted numbers without full production approval.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Set `VONAGE_API_KEY` and `VONAGE_API_SECRET` environment variables. Alternatively, you can pass them directly to `vonage.Client(key='YOUR_KEY', secret='YOUR_SECRET')` but avoid hardcoding in production.","message":"Authentication for `vonage.Client` typically uses API Key and Secret. Ensure these are correctly configured and kept secure, preferably via environment variables.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Ensure you have the latest `vonage-network-sim-swap` installed, which should pull in a compatible `vonage` SDK. Run `pip install --upgrade vonage-network-sim-swap` or `pip install --upgrade vonage`.","cause":"The `vonage` library version is too old and does not include the `sim_swap` client, or the `vonage-network-sim-swap` package (which pulls in `vonage`) was not installed correctly.","error":"AttributeError: 'Client' object has no attribute 'sim_swap'"},{"fix":"Verify your `VONAGE_API_KEY` and `VONAGE_API_SECRET` are correctly set in your environment variables or passed to the `vonage.Client` constructor. Regenerate them in the Vonage Dashboard if necessary.","cause":"The provided Vonage API Key and/or API Secret are incorrect or missing, leading to an authentication failure with the Vonage API.","error":"SIM Swap Check failed for +15551234567:   Error Code: 401   Error Message: Authentication failed: Invalid credentials"},{"fix":"Ensure the `phone_number` variable is formatted correctly, including the '+' and country code, for example, `'+15551234567'`.","cause":"The phone number provided to the Sim Swap API is not in the required E.164 format (e.g., missing the leading '+' or country code).","error":"SIM Swap Check failed for 15551234567:   Error Code: 400   Error Message: Invalid parameter: phone_number"},{"fix":"Navigate to your Vonage Dashboard, go to 'Applications', select your application, and enable the 'Network Registry' capability. Select 'Playground' for testing environments.","cause":"The 'Network Registry' capability has not been enabled for your Vonage Application in the Vonage Dashboard, which is necessary for accessing Sim Swap functionality.","error":"SIM Swap Check failed for +15551234567:   Error Code: NETWORK_REGISTRY_ERROR   Error Message: This feature requires Network Registry to be enabled for your application."}]}