# Examples for common API tasks (https://guides.dataportal.gov.lt/docs/api/guides/recipes)



The examples use the same population dataset as the [quickstart](https://guides.dataportal.gov.lt/docs/api/guides/overview). Start there if you need to locate the table before running a request.

## Find a dataset by its official code [#find-a-dataset-by-its-official-code]

Official statistics records carry a code such as `S3R167_M3010203` in `other_identifier`. The code is also indexed as a keyword. Use its lower-case form in the `keywords` filter.

```bash
curl -X POST 'https://api.dataportal.gov.lt/v1/datasets' \
  -H 'Content-Type: application/json' \
  -d '{"lang":"en","filters":{"keywords":{"parameters":["s3r167_m3010203"]}}}'
```

## Get a dataset's query links in one call [#get-a-datasets-query-links-in-one-call]

Request only `distribution`. For each table-backed distribution, the result includes its table and available `query` link.

```bash
curl 'https://api.dataportal.gov.lt/v1/datasets/sd001920?lang=en&fields=distribution.table_id'
```

## List every value of a column [#list-every-value-of-a-column]

Call `enums` for the exact values accepted by a column filter. Increase `limit` to retrieve more values per page.

```bash
curl 'https://api.dataportal.gov.lt/v1/datasets/sd001920/distributions/sdr001920_en/schema/administrative_territory/enums?lang=en&limit=100'
```

This example returns 74 territorial values, covering Lithuania, regions, counties and municipalities. Panevėžys city and Panevėžys district appear separately.

## Count matching rows without downloading them [#count-matching-rows-without-downloading-them]

Request one row, then read `total` for the number of rows matching the filter.

```bash
curl -X POST 'https://api.dataportal.gov.lt/v1/data/organizations/188600177/tables/S3R167_M3010203_en/query' \
  -H 'Content-Type: application/json' \
  -d "{\"filter\":\"sex='Males'\",\"select\":\"row_id\",\"limit\":1}"
# "total": 45880
```

Set `limit: 1`. A zero limit returns an error.

## Find the latest period [#find-the-latest-period]

Sort the period column in descending order and request the first row.

```bash
-d '{"select":"time_period","sort":"-time_period","limit":1}'
# { "data": [ { "time_period": "2026" } ], … }
```

<span id="one-municipality-by-age-group" className="ldp-anchor" />

## Population by age group in one municipality [#population-by-age-group-in-one-municipality]

The population of Panevėžys city by five-year age group, both sexes, in 2026 —
20 rows: 18 age groups from `0–4` to `85 and more`, `Not indicated` and
`Total by age`. The groups sort as text, so `5–9` lands after `55–59`:

```bash
curl -X POST 'https://api.dataportal.gov.lt/v1/data/organizations/188600177/tables/S3R167_M3010203_en/query' \
  -H 'Content-Type: application/json' \
  -d "{\"select\":\"age_5_year_groups,s3r167\",\"filter\":\"administrative_territory='Panevėžys c. mun.'&sex='Males and females'&time_period='2026'\",\"sort\":\"age_5_year_groups\",\"limit\":50}"
```

To include a second year, append `&_or.time_period='2025'` to the first year condition.

<span id="a-municipality-over-time" className="ldp-anchor" />

## Track a municipality’s population over time [#track-a-municipalitys-population-over-time]

Remove the year filter and keep the total for all ages. This gives one figure per year.

```bash
-d "{\"select\":\"time_period,s3r167\",\"filter\":\"administrative_territory='Panevėžys c. mun.'&sex='Males and females'&age_5_year_groups='Total by age'\",\"sort\":\"-time_period\",\"limit\":50}"
```

## What an organization published most recently [#what-an-organization-published-most-recently]

Filter by organisation and sort the results by update date.

```bash
curl -X POST 'https://api.dataportal.gov.lt/v1/datasets' \
  -H 'Content-Type: application/json' \
  -d '{"lang":"en","limit":5,"sort":"UpdatedDesc","filters":{"organization":{"parameters":["111958286"]}}}'
```

Use `GET /v1/datasets/filters/organization/values` to look up the organisation code.

## Statistics on a theme, for a period [#statistics-on-a-theme-for-a-period]

Combine the theme and coverage filters. The `LT_SOCI` theme includes Population and society and its subtopics.

```bash
-d '{"lang":"en","filters":{"theme":{"parameters":["LT_SOCI"]},"temporal_coverage":{"from":"2024-01-01","to":"2024-12-31"}}}'
```

## Export one municipality to Excel [#export-one-municipality-to-excel]

```bash
curl -X POST 'https://api.dataportal.gov.lt/v1/data/organizations/188600177/tables/S3R167_M3010203_en/export?format=xlsx' \
  -H 'Content-Type: application/json' \
  -d "{\"filter\":\"administrative_territory='Panevėžys c. mun.'\"}" \
  -o panevezys.zip
```

The workbook holds all 1,860 rows for Panevėžys city. For this filtered XLSX export, a result of 128 rows or more arrives in a ZIP archive. Extract the workbook before opening it. See [Downloading data](https://guides.dataportal.gov.lt/docs/api/guides/downloading#a-filtered-slice) for other export cases.

## The whole table for pandas [#the-whole-table-for-pandas]

Parquet preserves column types when you load the table into `pandas` for analysis. An export with no `limit` returns every row, so the whole table, 137,640 rows, comes in one request.

```python
import io
import pandas as pd
import requests

URL = "https://api.dataportal.gov.lt/v1/data/organizations/188600177/tables/S3R167_M3010203_en/export"

resp = requests.post(URL, params={"format": "parquet"}, json={})
resp.raise_for_status()
df = pd.read_parquet(io.BytesIO(resp.content))  # 137,640 rows
```

Parquet files are never zipped, so the response can be read directly. Add a `filter` to the body to load only part of the table.

## See also [#see-also]

* [Searching the catalogue](https://guides.dataportal.gov.lt/docs/api/guides/searching)
* [Querying tables](https://guides.dataportal.gov.lt/docs/api/guides/querying)
* [Downloading data](https://guides.dataportal.gov.lt/docs/api/guides/downloading)
