Getting started overview

KeyCDN's IP Location Finder allows developers to retrieve geographical information for an IP address. This typically includes details such as country, region, city, and coordinates. The service is integrated within the broader KeyCDN ecosystem, primarily accessed via a RESTful API. Integrating the IP Location Finder involves obtaining API credentials after creating a KeyCDN account, then formulating an HTTP GET request to the designated API endpoint with the target IP address and your authentication key.

The following table outlines the foundational steps for getting started:

Step What to Do Where to Do It
1. Account Creation Sign up for a KeyCDN account. KeyCDN Official Website
2. API Key Generation Generate an API key within your KeyCDN dashboard. KeyCDN Dashboard > Account > API
3. Understand Endpoint Review the API documentation for the IP Location Finder endpoint structure. KeyCDN IP Location Finder API Documentation
4. Make First Request Construct and execute an API call using your API key and a target IP. Your preferred development environment (e.g., cURL, Postman, Python script)

Create an account and get keys

To use the KeyCDN IP Location Finder API, you must first create an account on the KeyCDN platform. The IP Location Finder service is part of the KeyCDN offering, and its usage is typically tied into KeyCDN's overall CDN pricing structure, which includes various usage tiers as described on their pricing page. While there isn't an explicitly advertised free tier for the standalone IP Location Finder API, KeyCDN CDN plans often include free trials which may provide access to the API.

  1. Sign up for a KeyCDN Account: Navigate to the KeyCDN website and complete the registration process. This typically involves providing an email address and setting up a password.
  2. Access the Dashboard: Once your account is active, log in to the KeyCDN dashboard.
  3. Generate an API Key:
    • In the dashboard, locate the 'Account' section, usually found in the main navigation or sidebar.
    • Within the 'Account' section, look for an 'API' or 'API Settings' tab.
    • Follow the instructions to generate a new API key. This key is crucial for authenticating your requests to the IP Location Finder API. Keep your API key secure, as it grants access to your account's API usage.

The API key functions as a unique identifier and authentication token for your API calls. For security best practices, ensure that API keys are not hard-coded directly into client-side applications and are instead managed securely on a server-side component or through environment variables, as recommended for any API accessing sensitive data or resources in Google's API key best practices.

Your first request

Once you have your KeyCDN API key, you can make your first request to the IP Location Finder API. The API is a RESTful service, meaning you'll interact with it using standard HTTP methods, predominantly GET requests. The primary example provided by KeyCDN for interacting with their API is typically via cURL, a command-line tool for transferring data with URLs as documented by the cURL project.

The structure for an IP Location Finder API request involves a base URL, the API endpoint for IP lookup, and query parameters for the IP address and your API key.

API Endpoint Structure:

GET https://tools.keycdn.com/geo

Query Parameters:

  • host: The IP address you wish to look up (e.g., 8.8.8.8).
  • api_key: Your generated KeyCDN API key.

Example Request (using cURL):

Replace YOUR_API_KEY with your actual KeyCDN API key and TARGET_IP_ADDRESS with the IP you want to locate.

curl -X GET "https://tools.keycdn.com/geo?host=TARGET_IP_ADDRESS" \
     -H "User-Agent: KeyCDN-API-Client" \
     -H "api-key: YOUR_API_KEY"

Example Response (JSON format):

A successful response will return a JSON object containing the geographical details of the queried IP address. The exact fields may vary, but common ones include:

{
  "status": "success",
  "description": "IP lookup successful",
  "data": {
    "geo": {
      "ip": "8.8.8.8",
      "host": "dns.google",
      "rdns": "dns.google",
      "asn": 15169,
      "isp": "Google LLC",
      "country_name": "United States",
      "country_code": "US",
      "region_name": "California",
      "city": "Mountain View",
      "latitude": 37.4043,
      "longitude": -122.0747,
      "continent_code": "NA",
      "postal_code": "94043",
      "timezone": "America/Los_Angeles"
    }
  }
}

This JSON output provides structured data that your application can parse to extract the desired location information. For a full list of possible response fields, consult the KeyCDN IP Location Finder API documentation.

Common next steps

After successfully making your first IP lookup, consider these common next steps to integrate the IP Location Finder more deeply into your applications:

  1. Integrate into Application Logic: Parse the JSON response in your chosen programming language (e.g., Python, Node.js, PHP, Java). Extract specific fields like country, city, or coordinates to drive application features such as content localization, geo-targeting advertisements, or fraud detection.

  2. Error Handling: Implement robust error handling. The API response will include a status field (e.g., success or error) and a description. Your application should check these fields and respond appropriately to network issues, invalid IP addresses, or authentication failures.

  3. Rate Limiting and Usage Monitoring: Be aware of any rate limits imposed by KeyCDN to prevent abuse and ensure fair usage. Monitor your API usage through the KeyCDN dashboard to stay within your plan's limits and avoid unexpected charges. Consider implementing client-side rate limiting or caching mechanisms for frequently accessed IP addresses to reduce API calls.

  4. Secure API Keys: Reiterate the importance of keeping your API key secure. Do not embed it directly into front-end code. Use server-side proxies, environment variables, or secret management services (e.g., AWS Secrets Manager as described in AWS documentation or Google Cloud Secret Manager from Google Cloud's documentation) to protect your credentials.

  5. Explore Other KeyCDN Services: If your use case extends beyond basic IP lookup, explore other KeyCDN services, such as their CDN for content delivery, Origin Shield, or Image Processing, which can complement your IP location data.

  6. Review GDPR Compliance: KeyCDN states it is GDPR compliant. If your application processes personal data from users in the EU, understand your obligations under GDPR and how the IP Location Finder API fits into your data processing strategy.

Troubleshooting the first call

If your initial API call isn't returning the expected results, consider the following common issues and troubleshooting steps:

  • Invalid API Key: Double-check that you are using the correct API key generated from your KeyCDN dashboard. An incorrect key will typically result in an authentication error.

  • Incorrect Endpoint or Parameters: Verify that the API endpoint URL (https://tools.keycdn.com/geo) is precisely correct and that the host parameter contains a valid IP address. Ensure your API key is passed in the api-key header, not as a query parameter.

  • Network Connectivity Issues: Confirm that your environment has stable internet connectivity and that no firewalls or network policies are blocking outgoing requests to tools.keycdn.com.

  • Rate Limiting: If you are making multiple requests in quick succession, you might be hitting a rate limit. KeyCDN may temporarily block further requests. Wait a few moments and try again, or check your dashboard for specific rate limit details.

  • User-Agent Header: While often optional, some APIs prefer or require a User-Agent header. KeyCDN's example includes User-Agent: KeyCDN-API-Client. Ensure you include this or a similar descriptive user-agent string.

  • IP Address Format: Ensure the IP address you are querying is a valid IPv4 or IPv6 address. Invalid formats will cause the API to return an error.

  • Consult Documentation: Refer to the KeyCDN IP Location Finder API documentation for specific error codes and their meanings. The documentation provides the most up-to-date information on how to interpret API responses, including error conditions.

  • Check KeyCDN Dashboard: Your KeyCDN dashboard may offer API usage logs or error reports that can provide more insight into why a request is failing.