API Documentation
Complete API reference with ready-to-use code examples
API Overview
Base URL
https://api.iprating.net/api/v1
Authentication
All API requests require authentication using your API token as a query parameter.
?token=YOUR_API_TOKEN
Endpoints
GET /api/v1/{ip}
Get geolocation information for a specific IP address
Response Format
All responses are returned in JSON format with consistent structure.
{ "success": true, "data": { "ip": "1.2.3.4", "country": "US", "city": "New York", "latitude": 40.7128, "longitude": -74.0060, "timezone": "America/New_York", "isp": "Example ISP" }, "usage": { "requests_remaining": 9999 } }
Error Responses
Error responses include details about what went wrong.
{ "success": false, "error": { "code": "INVALID_IP", "message": "The provided IP address is not valid" } }
Code Examples
Ready-to-use code snippets for integrating with the IPrating.net API. All these examples include your API key by default, if you are logged in.
Basic Usage
// Basic IP lookup
const response = await fetch('https://api.iprating.net/api/v1/8.8.8.8?token=YOUR_API_TOKEN');
const data = await response.json();
if (data.success) {
console.log('Location:', data.data.city.names.en);
console.log('Country:', data.data.country.names.en);
console.log('Coordinates:', data.data.location.latitude, data.data.location.longitude);
}
Advanced Usage
// Advanced usage with error handling
async function getLocationData(ip) {
try {
const response = await fetch(`https://iprating.net/api/v1/${ip}?token=YOUR_API_TOKEN`);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
if (data.success) {
return {
city: data.data.city?.names?.en || 'Unknown',
region: data.data.subdivisions?.[0]?.names?.en || 'Unknown',
country: data.data.country?.names?.en || 'Unknown',
countryCode: data.data.country?.iso_code || 'Unknown',
latitude: data.data.location?.latitude || 0,
longitude: data.data.location?.longitude || 0,
timezone: data.data.location?.time_zone || 'Unknown',
isp: data.data.traits?.isp || 'Unknown'
};
} else {
throw new Error(data.error || 'API request failed');
}
} catch (error) {
console.error('Error fetching location data:', error);
return null;
}
}
// Usage
const locationData = await getLocationData('8.8.8.8');
console.log(locationData);