Authentication overview
IPInfoDB employs a straightforward authentication mechanism centered around a unique API key assigned to each user account. This key serves as the primary credential for accessing the IP Geolocation API endpoints. When making a request to the IPInfoDB API, this key must be supplied as a parameter, allowing the service to verify the user's identity and authorize the lookup.
The API key model is common for services providing public data access with usage limits, as it allows for tracking individual usage against defined quotas. While simple, proper handling of this key is crucial to prevent unauthorized access to your account's API usage, especially if using a paid tier with higher request allowances.
IPInfoDB's API is accessible via standard HTTP GET requests. All requests should be made over HTTPS to ensure the API key and any transmitted data are encrypted in transit, protecting against eavesdropping and tampering. The API provides endpoints for various IP lookup granularities, including city and country level data, all requiring the same API key for authentication.
Supported authentication methods
IPInfoDB supports a single, consistent authentication method across its API endpoints: API Key authentication.
| Method | When to Use | Security Level |
|---|---|---|
| API Key (Query Parameter) | All API requests to IPInfoDB | Moderate (Requires secure key management and HTTPS) |
API Key Authentication
The API key is a unique string assigned to your IPInfoDB account. It acts as a token that identifies you as an authorized user. When you send a request to the IPInfoDB API, you include this key as a query parameter in the URL. For instance, if your API key is YOUR_API_KEY, a request might look like https://api.ipinfodb.com/v3/ip-city/?key=YOUR_API_KEY&ip=8.8.8.8&format=json.
This method is straightforward to implement and monitor. The API key is directly tied to your account's usage limits, allowing IPInfoDB to enforce the free tier limits of 15,000 lookups per day, or higher limits for paid plans.
Getting your credentials
To obtain your IPInfoDB API key, you need to register for an account on their official website. The process involves a few steps:
- Visit the IPInfoDB Website: Navigate to the IPInfoDB homepage.
- Sign Up/Register: Look for a "Sign Up" or "Register" link. You will typically need to provide an email address, create a password, and agree to their terms of service.
- Verify Email (if required): Some registration processes include an email verification step to confirm your account.
- Access Your Dashboard: Once registered and logged in, you should be directed to your user dashboard or account management page.
- Locate Your API Key: On your dashboard, there will be a section specifically for your API key. It might be labeled "API Key," "My API Key," or similar. Copy this key, as it will be required for all your API requests. The IPInfoDB API documentation provides further guidance on where to find your key within the user interface.
Your API key is unique to your account and should be treated as a sensitive credential. IPInfoDB does not typically offer multiple API keys per account for different projects; instead, a single key manages all API usage associated with that account.
Authenticated request example
Here's an example of how to make an authenticated request to the IPInfoDB API using a hypothetical API key YOUR_API_KEY_HERE:
Example: IP Geolocation (City Level)
This example retrieves city-level geolocation data for a specified IP address (8.8.8.8, Google's public DNS server) in JSON format.
HTTP Request
GET https://api.ipinfodb.com/v3/ip-city/?key=YOUR_API_KEY_HERE&ip=8.8.8.8&format=json
Example Response (JSON)
{
"statusCode": "OK",
"statusMessage": "",
"ipAddress": "8.8.8.8",
"countryCode": "US",
"countryName": "United States",
"regionName": "California",
"cityName": "Mountain View",
"zipCode": "94043",
"latitude": "37.38605",
"longitude": "-122.08385",
"timeZone": "-07:00"
}
Using a Client Library (Python)
While IPInfoDB doesn't provide official client libraries, you can easily integrate it using common HTTP request libraries in various programming languages. Here's a Python example using the requests library:
import requests
API_KEY = "YOUR_API_KEY_HERE"
IP_ADDRESS = "8.8.8.8"
BASE_URL = "https://api.ipinfodb.com/v3/ip-city/"
params = {
"key": API_KEY,
"ip": IP_ADDRESS,
"format": "json"
}
try:
response = requests.get(BASE_URL, params=params)
response.raise_for_status() # Raise an exception for HTTP errors
data = response.json()
print(data)
except requests.exceptions.RequestException as e:
print(f"An error occurred: {e}")
Replace YOUR_API_KEY_HERE with your actual API key. This pattern applies to other programming languages as well; the core is to include the key parameter in your API request URL.
Security best practices
Securing your IPInfoDB API key is essential to prevent unauthorized usage and protect your account. Follow these best practices:
1. Keep Your API Key Confidential
- Do not embed directly in client-side code: Never hardcode your API key directly into JavaScript that runs in a web browser or mobile app. This exposes your key to anyone who inspects your code. For client-side applications, route requests through your own backend server that can securely hold and apply the API key.
- Use environment variables: When deploying applications, store your API key in environment variables rather than directly in your source code. This keeps the key out of version control and isolated from the application bundle. Most cloud platforms like Google Cloud and AWS support environment variables or secret management services.
- Restrict access: Limit who has access to your API key within your development team and infrastructure.
2. Always Use HTTPS
- Ensure all your API requests to IPInfoDB are made over HTTPS (
https://). This encrypts the entire communication, including your API key, protecting it from interception during transit over the internet. IPInfoDB's API documentation implicitly expects HTTPS usage, and the examples provided use it.
3. Implement Rate Limiting and Error Handling
- While IPInfoDB enforces its own rate limits, implementing client-side rate limiting can help prevent accidental overuse of your quota.
- Robust error handling in your application helps manage scenarios where the API key might be invalid or requests fail, preventing cascading issues.
4. Monitor API Usage
- Regularly check your IPInfoDB account dashboard for API usage statistics. This helps you detect any unexpected spikes in usage that could indicate unauthorized key compromise or an issue in your application.
5. Rotate API Keys
- Periodically regenerate your API key through your IPInfoDB account dashboard. This practice, known as key rotation, reduces the window of opportunity for a compromised key to be exploited. If you suspect your key has been compromised, revoke the old key and generate a new one immediately.
By adhering to these security best practices, developers can significantly reduce the risk associated with using API keys for IPInfoDB authentication, maintaining the integrity of their applications and account usage.