API documentation
Postcode API for Lithuania, Latvia and Estonia. Requests accept GET and POST methods, results are returned as application/json.
https://api.postapi.lt/api.phpRequest URL
All requests are sent to a single URL. Search and settings parameters are passed as URL parameters (GET) or in the request body (POST). The same API is also available at https://api.postapi.lt/search.
https://api.postapi.lt/api.php
Addresses are searched in Lithuania (default), Latvia and Estonia – the country is set with the country parameter.
Required and search parameters
keyrequiredAPI access key.
tokenA temporary token instead of key – when the request is sent from a browser and the key must not be visible in the page source.
Valid for 180 minutes. How to create one – see the “Token” section.
countryCountry: LT, LV or EE (case-insensitive).
If not set — LT. Any other value returns error 1006.
Search parameters
cityCity name or the beginning of it.
addressThe address in one line: street, house number and, if known, the city (e.g. Birutės g. 8, Klaipėda; Birutės 8).
A postcode (LT-91202), an apartment number (Laisvės pr. 44-78) and (in LT) small typos are recognised.
qSame as address (for compatibility with older modules). Used when address is not set.
streetStreet name or the beginning of it.
Ignored when the address parameter is used.
house_numberHouse number.
Ignored when the address parameter is used.
Can only be used together with another search parameter.
postcodePostcode or the beginning of it, without the country prefix (e.g. 91202, 912; LV 1050; EE 10119).
municipalityMunicipality name or the beginning of it.
post_officePost office name or the beginning of it.
lat, lonCoordinates (WGS84). Returns the nearest addresses sorted by distance; the distance in metres is in the distance field.
Can be combined with other search parameters (e.g. street).
max_distanceMaximum distance in metres for a coordinate search (150–10,000).
If not set — 500.
Search settings
limitNumber of records returned. Allowed values: 1 to 20.
If not set — 10 records are returned.
pagePage number of the results. Allowed values: 1 to the number of pages given by page.total in the response.
If not set — page 1 is returned.
autocomplete1 – search while typing: address is treated as text typed by the user, the last word as the beginning of a word.
Used by the JavaScript library. If not set — 0.
wide_number0 – exact house number only (10 → 10, 10A), 1 – number as a prefix (1 → 1, 10, 11…). LT only.
If not set — 0.
orderSort order of the results (not applied with autocomplete=1). Allowed fields: city, street, house_number, municipality, postcode.
Ascending: asc. Descending: desc.
Several fields can be combined (up to 3): order=city-asc.street-desc.
If not set — results are sorted automatically by relevance.
order=city-asc
order=city-asc.street-desc
Response
Results are returned as application/json.
{
"success": true,
"rows_returned": 1,
"total_found": 1,
"free_tier": false,
"data": [
{
"postcode_full": "LT-91202",
"postcode": "91202",
"street": "Birutės g.",
"house_number": "8",
"city": "Klaipėda",
"city2": "Klaipėdos m.",
"address": "Birutės g. 8",
"municipality": "Klaipėdos m. sav.",
"post_office": "",
"lat": 55.700359,
"lon": 21.140259,
"country": "LT"
}
],
"took_time": 0.003,
"took_time_ms": 3,
"page": {
"current": 1,
"total": 1,
"per_page": 10
}
}Response fields
successResult of the request: true or false.
true when the request was processed, even if no matching records were found.
false when required parameters are missing, the API key is invalid, the request limit is exceeded or a system error occurred.
rows_returnedNumber of records returned.
Not present when success is false.
total_foundTotal number of records found (0 – nothing found; this is not an error).
Not present when success is false.
free_tiertrue – the free plan is used: a link to PostAPI.lt is required on the website (see “Requirements”).
The JavaScript library shows the link automatically.
took_time_msRequest duration in milliseconds (took_time – in seconds).
address_apartmentApartment number recognised in the address text (Laisvės pr. 44-78 → 78). Only with autocomplete=1.
dataRecords found for the search parameters.
Empty when success is false.
pagePaging information.
Not present when success is false.
Record fields (in the data array)
postcode_fullPostcode with the country prefix, e.g. LT-91202, LV-1001, EE-10117 (full format).
postcodePostcode without the prefix (short format).
streetStreet name.
house_numberHouse number.
addressAddress — street name and house number.
cityCity or settlement name.
city2Settlement with its type or in genitive (e.g. Klaipėdos m.; EE Maardla küla).
municipalityMunicipality (LV novads, EE vald).
post_officePost office name (may be empty).
lat, lonAddress coordinates (WGS84).
distanceDistance in metres from the given point. Only for lat / lon searches.
countryCountry searched (LT, LV, EE).
Paging fields (in the page object)
currentCurrent page of the results.
totalNumber of result pages.
per_pageNumber of records per page.
Error messages
Errors are returned as application/json. On an error success is always false and the data array is empty. Check error_code in your code, not the message text.
{
"success": false,
"message": "Request limit exceeded.",
"error_code": 1002,
"data": []
}999Invalid token.The token is invalid.1000The token has expired.The token is older than 180 minutes.1001At least one search parameter is required.No search parameter was given.1002Request limit exceeded.The daily limit is reached or the request package is used up.1003The API key is invalid or expired.The API key is invalid or expired.1004An API key is required.No API key was given.1005Unexpected error. Please contact the system administrators.Internal error – please contact us.1006Unsupported country. Allowed values of the country parameter: LT, LV, EE.Unsupported value of the country parameter.Token
When requests are sent from a browser, the API key is visible in the page source. A temporary token can be passed instead: your server encrypts key;unix_time with the PostAPI public RSA key (OAEP) and passes the token to the page. The token is valid for 180 minutes.
$publicKey = file_get_contents("postapi-public.pem");
openssl_public_encrypt($apiKey . ";" . time(), $encrypted, $publicKey, OPENSSL_PKCS1_OAEP_PADDING);
$token = base64_encode($encrypted); // ?token=... instead of ?key=...Code examples
curl "https://api.postapi.lt/api.php?city=Klaipėda&address=Birutės+g.+8&key=API_KEY"
const params = new URLSearchParams({
city: "Klaipėda",
address: "Birutės g. 8",
key: API_KEY,
});
const response = await fetch(
`https://api.postapi.lt/api.php?${params}`,
);
const result = await response.json();
if (result.success) {
console.log(result.data);
}$query = http_build_query([ "city" => "Klaipėda", "address" => "Birutės g. 8", "key" => $apiKey, ]); $response = file_get_contents( "https://api.postapi.lt/api.php?" . $query ); $result = json_decode($response, true);
Requirements
With a free API key, a link to the PostAPI website must be placed on the website or in the application.
<small>Pašto kodų integracija - <a href="http://postapi.lt" target="_blank">PostAPI.lt</a></small>