Apartments API

Apartments API returns all the apartments of the given address. Works only for the Latvian addresses.

API URL

The request URL should match the following pattern:

https://api.kartes.lv/v3//apartments?`

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
address Hash code of the address (the hash parameter of the Search API).
limit Maximum number of returned objects. Up to 200 objects can be returned.

Response parameters

The response consists of an array of apartments.

Error codes

Status code Description
200 no address was passed. Cannot find hash code of the address.
404 No location found. The URL is not recognized; the resource does not exist.
5xx Server error.

Examples

Input:

https://api.kartes.lv/v3//apartments?address=a740281e9b3e4e90a269892d4ba477ca

Response:

[
    1,
    2,
    3,
    4,
    5
    ...
]

Use examples

Defining an apartments API class in JavaScript code:

class ApartmentApi {
    constructor() {
        this.apiKey = 'your_api_key_here'; // Replace with your actual API key
        this.baseUrl = 'https://api.kartes.lv/v3';
    }

    // Method to fetch apartment data by address
    async getApartmentData(address) {
        const url = `${this.baseUrl}/${this.apiKey}/apartments?address=${encodeURIComponent(address)}`;

        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 apartments API class:

const api = new ApartmentAPI();

api.getApartmentData('1395b000c9b0451c7c8fe5ca6de19e76')
    .then(result => {
        if (!result.success) {
            console.error('Error:', result.error); // Handle the error
            return;
        }

        console.log(result.data);
        // Use the data
    });