Documentation - API Usage Guide
Basics
The API offers precise and current geolocation data along with security information, accomplished through the detection or resolution of a targeted IP address. You can access this functionality through the following endpoints:
https://api.ip2loc.com/YOUR_API_KEY/detect?include=city
https://api.ip2loc.com/YOUR_API_KEY/161.185.160.93?include=city
Example API Response (default format is Json)
The API response is in JSON format by default and contains information about the target IP address. In this example, the requested data includes whether the country associated with the IP is a member of the European Union, as well as the country's flag emoji. The response returns the corresponding data in a JSON object, including the country's flag emoji represented as Unicode, and a boolean value indicating whether the country is an EU member.
https://api.ip2loc.com/YOUR_API_KEY/detect?include=city
https://api.ip2loc.com/YOUR_API_KEY/161.185.160.93?include=city
Available data via include parameter
The available data that can be retrieved from the API by using the "include" parameter are as follows:
Parameter & Example
capital: ""Washington D.C."(string)
city: "Brooklyn"" (string)
continent_code: "NA" (string)
continent_name: North America (string)
country_alpha_2: US (string)
country_alpha_3: USA (string)
country_dialing_code: [1] (string[])
country_emoji: "🇺🇸" (string)
country_eu_member: false (bool)
country_name: "United States" (string)
country_subdivision: "New York" (string)
country_subdivision_id: "NY" (string)
country_zip_code: "11205" (string)
currency_code: ["USD","USN","USS"] (string[])
ip: "161.185.160.93" (string)
ip_version: 4 (int)
is_proxy: false (bool)
is_tor: false (bool)
location_latitude: 40.6955 (float)
location_longitude: -73.9667 (float)
proxy_type: null (string|null)
success: true (bool)//successful or failed
time_zone: "America/New_York" (string)
Code Snippets
React example
fetch("https://api.ip2loc.com/YOUR_API_KEY/detect?include=country_eu_member")
.then(response => response.json())
.then(response => {
if (response.success) {
if (response.country_eu_member) {
showGdpr()
}
}
});
Ajax example
$.getJSON("https://api.ip2loc.com/YOUR_API_KEY/detect?include=country_eu_member,ip", function(result){
if(result.country_eu_member){
$("div").append(result.ip);
}
});
PHP example
$ch = curl_init('https://api.ip2loc.com/YOUR_API_KEY/detect?include=country_eu_member');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
$response = json_decode($result, true);
echo $response['country_eu_member'];
curl example
curl https://api.ip2loc.com/YOUR_API_KEY/detect?include=country_eu_member
curl example
https://api.ip2loc.com/YOUR_API_KEY/161.185.160.93
{
connection: {
ip: "161.185.160.93",
ip_version: "4"
},
currency: {
code: [
"USD",
"USN",
"USS"
]
},
location: {
capital: "Washington D.C.",
city: "New York",
continent: {
code: "NA",
name: "North America"
},
country: {
alpha_2: "US",
alpha_3: "USA",
dialing_code: [
"1"
],
emoji: "🇺🇸",
eu_member: false,
name: "United States",
subdivision: "New York",
subdivision_id: "NY",
zip_code: "10003"
},
latitude: 40.7359,
longitude: -73.9904
},
security: {
is_proxy: false,
is_tor: false,
proxy_type: null
},
success: true,
time: {
zone: "America/New_York"
}
}