Verify Geolocation & Compliance

This guide shows how to use the Whisper API's IP Intelligence endpoint to get accurate, real-time geolocation data. This capability is essential for everything from localizing content and preventing fraud to ensuring your data handling meets strict regulatory compliance standards like GDPR.

Goal: Know Where Your Users Are

Understanding the geographic location of an IP address is fundamental for many applications. Whether you need to comply with data sovereignty laws, customize user experiences, or perform risk analysis, precise geolocation data is critical.

Accessing Geolocation Data

The GET /intelligence/v1/ip/{address} endpoint provides a rich geolocation object in its JSON response.

When you query an IP, you'll receive the following key fields:

  • geolocation.country: Contains the country's name and standard iso_code (e.g., "US").
  • geolocation.city: Provides the name of the city.
  • geolocation.coordinates: Gives you the precise latitude and longitude, along with an accuracy_radius in kilometers.
  • geolocation.postal_code: The postal code for the location.
  • geolocation.time_zone: The IANA time zone name (e.g., "America/Los_Angeles").

Common Applications

Here are a few ways you can use this data:

  1. Data Compliance: Before storing user data, check the IP's country.iso_code. If it's in a region covered by GDPR or another data privacy law, you can trigger the appropriate consent mechanisms or data handling workflows.
  2. Content Localization: Customize your website or application by reading the country.iso_code. You can automatically set the correct language, currency, and display region-specific content.
  3. Fraud Prevention: In e-commerce, you can compare the IP's location with the billing or shipping address provided by the user. A significant mismatch could be a flag for a fraudulent transaction.
  4. Analytics: Enhance your user analytics by mapping usage patterns to geographic locations, helping you understand your audience and market penetration.

Python Code Example

This code snippet demonstrates how to fetch and display key geolocation data for an IP address using the Python SDK.

import noctis_frontgraph_sdk
from noctis_frontgraph_sdk.rest import ApiException
import os

# Configure authentication
configuration = noctis_frontgraph_sdk.Configuration(access_token = os.environ["BEARER_TOKEN"])

with noctis_frontgraph_sdk.ApiClient(configuration) as api_client:
    api_instance = noctis_frontgraph_sdk.IntelligenceServicesApi(api_client)
    ip_address = '8.8.8.8' 

    try:
        # Get comprehensive IP address intelligence
        api_response = api_instance.get_ip_intelligence(ip_address)
        
        # Extract and print the geolocation object
        geo_data = api_response.geolocation
        print(f"Geolocation data for IP: {ip_address}")
        print(f"  Country: {geo_data.country.name} ({geo_data.country.iso_code})")
        print(f"  City: {geo_data.city.name}")
        print(f"  Coordinates: Lat {geo_data.coordinates.latitude}, Lon {geo_data.coordinates.longitude}")
        print(f"  Time Zone: {geo_data.coordinates.time_zone}")

    except ApiException as e:
        print("Exception when calling IntelligenceServicesApi->get_ip_intelligence: %s\n" % e)