GetIPLoc API Documentation
Use our API to get accurate IP location data in seconds.
🚀 Quick Integration (Laravel)
After registering your website, GetIPLoc automatically generates a unique
Site API Token. Copy your token from the dashboard and use it in your
Laravel controller to fetch IP Intelligence.
Step 1 - Copy Your API Token
Your API token is available in your dashboard after sign-up.
Keep it secure and never expose it publicly.
Step 2 - Add this code inside your Controller
use Illuminate\Support\Facades\Http;
public function index()
{
$ip = request()->ip();
$apiToken = 'YOUR_SITE_API_TOKEN';
try {
$response = Http::withHeaders([
'X-API-KEY' => $apiToken,
'Accept' => 'application/json',
])
->get("https://getiploc.com/api/ip/" . $ip);
$data = $response->json();
return $data;
} catch (\Exception $e) {
return $e->getMessage();
}
}
Step 3 - Example Response
{
"status": true,
"data": {
"IP Address": "223.181.125.207",
"Country": "India",
"State": "Karnataka",
"City": "Bengaluru",
"ISP": "Bharti Airtel Ltd.",
"ASN Number": 24560
},
"usage": {
"limit": 20000,
"used": 120,
"remaining": 19880
}
}
🔐 Authentication
Each website uses its own site API token for tracking, analytics, and IP API requests.
Header:
X-API-KEY: YOUR_SITE_API_TOKEN
🧭 Tracking Script
Growth and Business users can generate per-site tracking APIs from the dashboard,
then add the tracker to the website footer.
<script src="https://www.getiploc.com/tracker.js?token=YOUR_SITE_API_TOKEN"></script>
🪵 Browser JSON Debug Mode
For development or QA, enable debug mode to inspect both the outbound packet and the resolved visitor
array in the browser console.
<script src="https://www.getiploc.com/tracker.js?token=YOUR_SITE_API_TOKEN&debug=1"></script>
With debug=1, the browser console prints the request payload, the resolved visitor data, and
stores the current request packet on window.__GETIPLOC_TRACKER_PACKET__.
{
"api_token": "YOUR_SITE_API_TOKEN",
"page_url": "https://example.com/pricing",
"referrer": "https://google.com/",
"user_agent": "Mozilla/5.0 ..."
}
🌍 Visitor Variables In tracker.js
After the tracker call succeeds, GetIPLoc exposes the resolved visitor context in the browser so
consumers can apply location-specific pricing, content, compliance, or personalization rules.
window.__GETIPLOC_TRACKER_VISITOR__
window.GETIPLOC_TRACKER.visitor
window.GETIPLOC_VISITOR_RAW
window.GETIPLOC_VISITOR
{
"IP Address": "23.120.11.4",
"Country": "United States",
"Country Code": "US",
"Continent": "North America",
"State": "Texas",
"City": "Pflugerville",
"Postal Code": "78660",
"Latitude": 30.4421,
"Longitude": -97.6339,
"Timezone": "America/Chicago",
"Accuracy Radius": "5 KM",
"ISP": "AT&T Enterprises, LLC",
"ASN Number": 7018,
"Browser": "Chrome",
"Device Type": "Desktop"
}
Use the tracker-ready event when the client script needs the resolved location before rendering page
logic.
window.addEventListener('getiploc:ready', function (event) {
const visitor = event.detail.visitor;
if (!visitor) return;
if (visitor['Country Code'] === 'IN') {
console.log('Show INR pricing');
}
console.log(visitor['Country']);
console.log(visitor['City']);
console.log(visitor['IP Address']);
console.log(visitor['ISP']);
console.log(visitor['ASN Number']);
});
🧠 Footer Session Loader
If the client wants one copy-paste footer script that caches the visitor array for the active browser
session and avoids repeat tracker round trips from the same tab session, use this loader instead of the
plain tracker script tag.
<script>
(function () {
var GETIPLOC_TOKEN = 'YOUR_SITE_API_TOKEN';
var GETIPLOC_HOST = 'https://www.getiploc.com';
var GETIPLOC_CACHE_KEY = 'getiploc_visitor_session_v1';
var GETIPLOC_DEBUG = false;
function normalizeVisitor(raw) {
if (!raw) return null;
return {
raw: raw,
ipAddress: raw['IP Address'] || null,
country: raw['Country'] || null,
countryCode: raw['Country Code'] || null,
continent: raw['Continent'] || null,
state: raw['State'] || null,
city: raw['City'] || null,
postalCode: raw['Postal Code'] || null,
latitude: raw['Latitude'] || null,
longitude: raw['Longitude'] || null,
timezone: raw['Timezone'] || null,
accuracyRadius: raw['Accuracy Radius'] || null,
isp: raw['ISP'] || null,
asnNumber: raw['ASN Number'] || null,
browser: raw['Browser'] || null,
deviceType: raw['Device Type'] || null
};
}
function readCachedVisitor() {
try {
var raw = sessionStorage.getItem(GETIPLOC_CACHE_KEY);
if (!raw) return null;
var parsed = JSON.parse(raw);
return parsed && parsed.raw ? parsed.raw : null;
} catch (e) {
return null;
}
}
function writeCachedVisitor(rawVisitor) {
try {
sessionStorage.setItem(GETIPLOC_CACHE_KEY, JSON.stringify({
cachedAt: Date.now(),
raw: rawVisitor
}));
} catch (e) {}
}
function clearCachedVisitor() {
try {
sessionStorage.removeItem(GETIPLOC_CACHE_KEY);
} catch (e) {}
}
function publishVisitor(rawVisitor, source) {
var visitor = normalizeVisitor(rawVisitor);
window.__GETIPLOC_TRACKER_VISITOR_RAW__ = rawVisitor;
window.__GETIPLOC_TRACKER_VISITOR__ = visitor;
window.GETIPLOC_VISITOR_RAW = rawVisitor;
window.GETIPLOC_VISITOR = visitor;
window.GETIPLOC_GET_SESSION_VISITOR = function () {
return readCachedVisitor();
};
window.GETIPLOC_CLEAR_SESSION_VISITOR = clearCachedVisitor;
window.dispatchEvent(new CustomEvent('getiploc:ready', {
detail: {
source: source,
raw: rawVisitor,
visitor: visitor
}
}));
if (GETIPLOC_DEBUG) {
console.groupCollapsed('[GETIPLOC CACHE] Visitor session data');
console.log('Source:', source);
console.table(rawVisitor);
console.log('Normalized:', visitor);
console.groupEnd();
}
}
var cachedVisitor = readCachedVisitor();
if (cachedVisitor) {
publishVisitor(cachedVisitor, 'session');
return;
}
var previousReady = window.GETIPLOC_TRACKER_READY;
window.GETIPLOC_TRACKER_READY = function (state) {
var rawVisitor = state && state.visitor ? state.visitor : null;
if (rawVisitor) {
writeCachedVisitor(rawVisitor);
publishVisitor(rawVisitor, 'network');
}
if (typeof previousReady === 'function') {
previousReady(state);
}
};
var script = document.createElement('script');
script.src =
GETIPLOC_HOST +
'/tracker.js?token=' +
encodeURIComponent(GETIPLOC_TOKEN) +
(GETIPLOC_DEBUG ? '&debug=1'
: '');
script.async = true;
document.head.appendChild(script);
})();
</script>
This is the recommended footer integration when the client wants to reuse the same resolved visitor array
throughout the active tab session.
var visitor = window.__GETIPLOC_TRACKER_VISITOR__ || null;
if (visitor) {
console.log(visitor['Country']);
console.log(visitor['City']);
console.log(visitor['IP Address']);
console.log(visitor['ASN Number']);
}
For development or testing, set var GETIPLOC_DEBUG = true; inside the loader so the client
developer can inspect the request and resolved visitor data in the console.
Important: this session-caching loader reduces repeat tracker traffic from the same
active browser session, but repeated page views from that same tab session will not be sent again to
GetIPLoc analytics until the cache is cleared or the session ends.
🌐 Endpoint
GET https://www.getiploc.com/api/ip/{ip}
📥 Example Request
GET https://www.getiploc.com/api/ip/8.8.8.8
Headers:
X-API-KEY: YOUR_SITE_API_TOKEN
📤 Example Response
{
"status": true,
"data": {
"IP Address": "8.8.8.8",
"Country": "United States",
"Country Code": "US",
"City": "Mountain View",
"ISP": "Google LLC"
},
"usage": {
"limit": 20000,
"used": 120,
"remaining": 19880
}
}
💻 JavaScript Example
fetch("https://www.getiploc.com/api/ip/8.8.8.8", {
headers: {
"X-API-KEY": "YOUR_SITE_API_TOKEN"
}
})
.then(res => res.json())
.then(data => console.log(data));
🐘 PHP Example
$options = [
"http" => [
"method" => "GET",
"header" => "X-API-KEY: YOUR_SITE_API_TOKEN"
]
];
$context = stream_context_create($options);
$response = file_get_contents("https://www.getiploc.com/api/ip/8.8.8.8", false, $context);
$data = json_decode($response, true);
print_r($data);
🔥 Laravel Example
$response = Http::withHeaders([
'X-API-KEY' => 'YOUR_SITE_API_TOKEN'
])->get("https://www.getiploc.com/api/ip/8.8.8.8");
$data = $response->json();
⚡ Dynamic IP Example
$userIp = request()->ip();
$response = Http::withHeaders([
'X-API-KEY' => 'YOUR_SITE_API_TOKEN'
])->get("https://www.getiploc.com/api/ip/$userIp");
$data = $response->json();
// Country
echo $data['data']['Country'] ?? 'N/A';
// Usage
echo "Limit: " . ($data['usage']['limit'] ?? 0);
echo "Used: " . ($data['usage']['used'] ?? 0);
echo "Remaining: " . ($data['usage']['remaining'] ?? 0);
// Error handle
if(!$response->successful()){
echo $data['message'];
}
❌ Error Responses
401 - API Token missing
401 - Invalid API Token
429 - API limit reached
📊 Rate Limit
Free Plan → 20,000 requests
After limit → API will stop responding