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 "https://api2.locatorhq.com/?ip=203.0.113.10&format=json" \
-H "Authorization: Bearer YOUR_API_KEY"
{
"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.
| Mode | How | Notes |
|---|---|---|
| Bearer recommended | Authorization: Bearer YOUR_API_KEY | Keeps the key out of URLs and logs. |
| Legacy | user + key as query or form parameters | Both values are required and must match. |
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
https://api2.locatorhq.com/
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
ip | string | yes | IPv4 or IPv6 literal to look up. Without it the response is NO DATA. |
format | string | no | json, JSON, xml or XML. Any other or missing value - including mixed case like Json - falls back to plain text. |
| credentials | - | yes | Bearer header, or user + key. See Authentication. |
Responses
{"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.
<ip2locationapi><countryCode>GB</countryCode><countryName>United Kingdom</countryName><region>Suffolk</region><city>Ipswich</city><latitude>52.0618</latitude><longitude>1.156</longitude></ip2locationapi>
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
0in JSON and0in text and XML; a missing longitude stays-. - A real
0coordinate is emitted as"0". - Missing, invalid or non-public IPs - private ranges, multicast, scope IDs - and lookup misses return
200 text/plainwith the exact bodyNO DATA, whatever format was requested.
v2 endpoint
https://api2.locatorhq.com/v2/
/v2 and /v2/ are equivalent (no redirect).
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
ip | string | yes | IPv4 or IPv6 literal. |
format | string | yes | Exactly json, JSON, xml, XML, text or TEXT. |
useragent | string | no | Up to 1 KiB. Profiled for the browser, OS and device fields. |
referrer | string | no | Up to 2 KiB. Classified for the entry fields; the URL is never fetched. |
mapwidth, mapheight | integer | no | Both decimal integers from 1 to 640, otherwise they default to 488×226. |
| credentials | - | yes | Same 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 "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
| Key | Type | Description |
|---|---|---|
| Location | ||
countryCode | string | Current MaxMind English value; "" when absent. |
countryName | string | As above. |
regionName | string | As above. |
cityName | string | As above. |
countryFlag | string | First available flag URL (-128.png) or "" for unknown countries. |
cityLattitude | string | 0 | String when present, numeric 0 when missing. Historic spelling kept. |
cityLongitude | string | 0 | As above. |
cityMap | string | Overview map URL, or "" when either coordinate is absent. |
Browser profile - from useragent, best-effort estimates | ||
browserName | string | null | null when unmatched. |
browserVersion | string | null | As above. |
browserFamily | string | null | As above. |
browserCookies | string | null | Cookie capability. |
browserJavascript | string | null | JavaScript capability. |
browserCSSVersion | string | null | CSS capability. |
osName | string | null | Operating system label. |
deviceType | string | null | Device label. |
Referrer - from referrer | ||
entryKeyword | string | Decoded search query: q for Google, Bing and MSN, p for Yahoo. |
entrySource | string | Google, Yahoo or Bing. Everything else is Direct Visit. |
entryDomain | string | The referring host. |
v2 XML five groups under <ip2locationapi>
| Group | Children |
|---|---|
countryData | countryCode, countryName, countryFlags - one countryFlag per available size (or one empty element) |
cityData | cityName, cityLattitude, cityLongitude, cityMap |
regionData | regionName |
browserData | Eight browser fields - blank when unmatched. |
sourceData | entryKeyword, 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:
countryCode,countryName- One form-URL-encoded flag URL per size (one empty field when none)
region,city,latitude,longitude,mapURLbrowserName,browserVersion,browserFamily,cookies,javascript,cssVersion,osName,deviceTypekeyword,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:
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
| Status | Body | Meaning |
|---|---|---|
| 200 | NO DATA | Valid request, no record. |
| 400 | BAD REQUEST | Duplicate or ambiguous fields, mixed auth modes. |
| 401 | UNAUTHORIZED | Missing, invalid or revoked credential. |
| 413 | PAYLOAD TOO LARGE | Request over size cap. |
| 415 | UNSUPPORTED MEDIA TYPE | Non-form POST body. |
| 429 | TOO MANY REQUESTS | Throttled; respect Retry-After. |
| 503 | SERVICE UNAVAILABLE | Backend 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
formatnow 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*.phpvariants 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.