Address Validation API
The API validates the given address of specified parameters.
API URL
The request URL should match the following pattern:
https://api.kartes.lv/v3//verify_address?
Noklusētais The response is given in JSON.
The HTTP GET request method is used.
Query parameters
The request consists of the following GET parameters:
Parameter | Description |
---|---|
iela | Street name |
maja | House number or name |
valsts | Country |
admin_vien | Administrative unit. |
terit_vien | Territorial unit. |
apdz_vieta | Populated place (city, town or village). |
index | Postal code. |
korpuss | Building block number. |
Response parameters
The response consists of a count of addresses matching the parameters.
Error codes
Status code | Description |
---|---|
200 | Wrong input data. Server can’t respond due to client error. |
404 | No location found. The URL is not recognized; the resource does not exist. |
5xx | Server error. |
Examples
Input:
https://api.kartes.lv/v3//verify_address?valsts=Latvija&iela=Krasta iela&maja=105A&admin_vien=Rīga&apdz_vieta=Rīga&terit_vien=Latgales priekšpilsēta&index=LV-1019
Response:
{"address":1}
Use examples
Defining an address verification API class in JavaScript code:
class VerifyAddressApi {
constructor() {
this.apiKey = 'your_api_key_here'; // Replace with your actual API key
this.baseUrl = 'https://api.kartes.lv/v3';
}
// Method to verify address
async verifyAddress({country, street, house, admin_unit, place, territ_unit, index}) {
const params = new URLSearchParams({
valsts: country,
iela: street,
maja: house,
admin_vien: admin_unit,
apdz_vieta: place,
terit_vien: territ_unit,
index: index
});
const url = `${this.baseUrl}/${this.apiKey}/verify_address?${params.toString()}`;
try {
const response = await fetch(url);
// Check if the response is ok (status code 200-299)
if (!response.ok) {
throw new Error(`Error fetching data: ${response.statusText}`);
}
const data = await response.json();
return { success: true, data };
} catch (error) {
console.error('Fetch error:', error);
return { success: false, error: error.message };
}
}
}
Using the address verification API class:
const api = new VerifyAddressAPI();
api.verifyAddress({
country: 'Latvija',
street: 'Krasta iela',
house: '105A',
admin_unit: 'Rīga',
place: 'Rīga',
territ_unit: 'Latgales priekšpilsēta',
index: 'LV-1019'
})
.then(result => {
if (!result.success) {
console.error('Error:', result.error); // Handle the error
return;
}
console.log('Address count:', result.data.address);
// Use the data
});