LocatorHQ

API documentation

Two versioned endpoints share one API key, one authentication scheme and one combined daily usage meter. Examples use placeholders - substitute your own key from the dashboard.

Base URL
https://api2.locatorhq.com
Transport
HTTPS only
Formats
JSON, XML, text
Methods
GET, form-encoded POST

Quick start

cURL request
curl "https://api2.locatorhq.com/?ip=203.0.113.10&format=json" \
     -H "Authorization: Bearer YOUR_API_KEY"
JSON 200 OK - illustrative data
{
  "countryCode": "GB",
  "countryName": "United Kingdom",
  "region": "Suffolk",
  "city": "Ipswich",
  "latitude": "52.0618",
  "longitude": "1.156"
}

Authentication

Every lookup needs a valid API key. New accounts issue keys from the dashboard; keys are shown once at issuance. Use one of two interchangeable credential modes.

ModeHowNotes
Bearer recommendedAuthorization: Bearer YOUR_API_KEYKeeps the key out of URLs and logs.
Legacyuser + key as query or form parametersBoth values are required and must match.
cURL legacy mode
curl "https://api2.locatorhq.com/?ip=203.0.113.10&format=json&user=YOUR_HANDLE&key=YOUR_API_KEY"

Form-encoded POST is accepted on both endpoints. Missing, invalid or revoked credentials return 401 UNAUTHORIZED.

Do not combine the modes. A request carrying both returns 400. Never send keys over plaintext HTTP - the API boundary rejects it outright.

Root endpoint

GETPOST https://api2.locatorhq.com/

Parameters

NameTypeRequiredDescription
ipstringyesIPv4 or IPv6 literal to look up. Without it the response is NO DATA.
formatstringnojson, JSON, xml or XML. Any other or missing value - including mixed case like Json - falls back to plain text.
credentials-yesBearer header, or user + key. See Authentication.

Responses

JSON format=json
{"countryCode":"GB","countryName":"United Kingdom","region":"Suffolk","city":"Ipswich","latitude":"52.0618","longitude":"1.156"}

Six keys in fixed order: countryCode, countryName, region, city, latitude, longitude. Present values are strings, including coordinates.

XML format=xml
<ip2locationapi><countryCode>GB</countryCode><countryName>United Kingdom</countryName><region>Suffolk</region><city>Ipswich</city><latitude>52.0618</latitude><longitude>1.156</longitude></ip2locationapi>
Text default
GB,United Kingdom,Suffolk,Ipswich,52.0618,1.156,203.0.113.10

An unquoted comma join of the six values, your IP as the seventh value, then a newline.

Text is not escaped CSV. Place names may contain separators; prefer JSON or XML when that matters.

Missing values and misses

  • A missing field inside a found record renders -.
  • A missing latitude is numeric 0 in JSON and 0 in text and XML; a missing longitude stays -.
  • A real 0 coordinate is emitted as "0".
  • Missing, invalid or non-public IPs - private ranges, multicast, scope IDs - and lookup misses return 200 text/plain with the exact body NO DATA, whatever format was requested.

v2 endpoint

GETPOST https://api2.locatorhq.com/v2/

/v2 and /v2/ are equivalent (no redirect).

Parameters

NameTypeRequiredDescription
ipstringyesIPv4 or IPv6 literal.
formatstringyesExactly json, JSON, xml, XML, text or TEXT.
useragentstringnoUp to 1 KiB. Profiled for the browser, OS and device fields.
referrerstringnoUp to 2 KiB. Classified for the entry fields; the URL is never fetched.
mapwidth, mapheightintegernoBoth decimal integers from 1 to 640, otherwise they default to 488×226.
credentials-yesSame as the root endpoint.

User agent and referrer come only from the parameters - never from your request headers.

A missing or unaccepted format returns a fixed HTML hint - “Please specify a response format. JSON, XML or Text” - with status 200 and no usage count.

cURL with user agent and referrer
curl "https://api2.locatorhq.com/v2/?ip=203.0.113.10&format=json&useragent=Mozilla%2F5.0%20(Windows%20NT%2010.0)&referrer=https%3A%2F%2Fwww.google.com%2Fsearch%3Fq%3Dwidgets" \
     -H "Authorization: Bearer YOUR_API_KEY"

v2 JSON fields 19, in order

KeyTypeDescription
Location
countryCodestringCurrent MaxMind English value; "" when absent.
countryNamestringAs above.
regionNamestringAs above.
cityNamestringAs above.
countryFlagstringFirst available flag URL (-128.png) or "" for unknown countries.
cityLattitudestring | 0String when present, numeric 0 when missing. Historic spelling kept.
cityLongitudestring | 0As above.
cityMapstringOverview map URL, or "" when either coordinate is absent.
Browser profile - from useragent, best-effort estimates
browserNamestring | nullnull when unmatched.
browserVersionstring | nullAs above.
browserFamilystring | nullAs above.
browserCookiesstring | nullCookie capability.
browserJavascriptstring | nullJavaScript capability.
browserCSSVersionstring | nullCSS capability.
osNamestring | nullOperating system label.
deviceTypestring | nullDevice label.
Referrer - from referrer
entryKeywordstringDecoded search query: q for Google, Bing and MSN, p for Yahoo.
entrySourcestringGoogle, Yahoo or Bing. Everything else is Direct Visit.
entryDomainstringThe referring host.

v2 XML five groups under <ip2locationapi>

GroupChildren
countryDatacountryCode, countryName, countryFlags - one countryFlag per available size (or one empty element)
cityDatacityName, cityLattitude, cityLongitude, cityMap
regionDataregionName
browserDataEight browser fields - blank when unmatched.
sourceDataentryKeyword, entrySource, entryDomain - the last two carry the host padded with one space on each side, e.g. www.google.com

v2 text

An unquoted comma join with no trailing newline and no trailing IP, in this order:

  1. countryCode,countryName
  2. One form-URL-encoded flag URL per size (one empty field when none)
  3. region,city,latitude,longitude,mapURL
  4. browserName,browserVersion,browserFamily,cookies,javascript,cssVersion,osName,deviceType
  5. keyword,domain,source,osName - the OS value repeats as the last field

Column count varies with flag cardinality, and free text can contain commas. Prefer JSON or XML for parsing.

Flags and map image

countryFlag and countryFlags URLs point at /assets/flags/<iso>-128.png and /assets/flags/<iso>-64.png on the API host. Only those packaged basenames exist; an unknown country produces an empty flag field, never a broken URL.

cityMap is a public PNG endpoint for the lookup overview only:

GET https://api2.locatorhq.com/v2/map.png?lat=<lat>&lon=<lon>&width=<1-640>&height=<1-640>

All four parameters are required exactly once; anything else is rejected. It needs no API key and carries its own rate limit - it is not a general tile service.

Errors

StatusBodyMeaning
200NO DATAValid request, no record.
400BAD REQUESTDuplicate or ambiguous fields, mixed auth modes.
401UNAUTHORIZEDMissing, invalid or revoked credential.
413PAYLOAD TOO LARGERequest over size cap.
415UNSUPPORTED MEDIA TYPENon-form POST body.
429TOO MANY REQUESTSThrottled; respect Retry-After.
503SERVICE UNAVAILABLEBackend or data outage - retry later.

All responses include Cache-Control: no-store.

Metering and limits

Successful data-bearing lookups on either version add one unit to a single combined daily meter, counted by UTC day and visible on your dashboard for the last 30 days.

Counts

Successful data-bearing lookups on the root or v2 endpoint.

Never counts

Misses, errors, format hints, throttled requests, flag images and map renders.

Technical throttles apply per source and per account; honor Retry-After.

Migrating from the legacy API

  • New credentials required. Legacy user/key pairs are not carried over - register, then issue a fresh key.
  • HTTPS only. Plaintext API requests are rejected, not redirected.
  • v2 requires an explicit format. Requests without an accepted format now get the HTML hint instead of a text default.
  • New asset hosts. Flag and map URLs are self-hosted absolute URLs built from the API origin - update hard-coded legacy hosts.
  • Changed source data. Names, flags and browser profiles come from current MaxMind/Browscap data and will differ from the old service.
  • Both versions are current. The root and v2 endpoints are live and supported - v2 is not retired or deprecated.
  • Historical script aliases retired. Old index*.php variants are gone; only the documented paths exist.
  • ASN data is provisioned for operations but is not exposed in any response.

GeoLite2 data by MaxMind; browser profiles by browscap.org; map imagery by Natural Earth (public domain). Locations are approximate.