# Understand API errors (https://guides.dataportal.gov.lt/docs/api/guides/errors)



A successful request has a 2xx HTTP status. If a request fails, inspect both the status code and the response body. The metadata routes and the data routes use different error formats.

## Metadata routes [#metadata-routes]

These examples cover `/v1/collections`, `/v1/search`, `/v1/datasets`, `/v1/classifications`, `/v1/reuses`, `/v1/organizations` and their metadata subroutes.

<ErrorExplorer
  lang="en"
  errors="[
  {
    code: 400,
    name: &#x22;Unknown filter, sort or field&#x22;,
    cause: &#x22;filters names a filter the collection does not have, sort is not one of its sort ids, or fields names a field that does not exist.&#x22;,
    body: { status: 400, title: &#x22;Unknown filters: bogus. Use keys returned by /filters.&#x22; },
    fix: &#x22;Take filter and sort ids from GET /v1/{collection}/filters, and field names from a full record (mode=full).&#x22;,
  },
  {
    code: 400,
    name: &#x22;Invalid request&#x22;,
    cause: &#x22;A value breaks the request's rules: limit outside 1–10,000, page × limit over 10,000, an unknown lang, a date that is not YYYY-MM-DD.&#x22;,
    body: {
      type: &#x22;https://tools.ietf.org/html/rfc9110#section-15.5.1&#x22;,
      title: &#x22;One or more validation errors occurred.&#x22;,
      status: 400,
      errors: { Page: [&#x22;page * limit must not exceed 10000.&#x22;], Limit: [&#x22;page * limit must not exceed 10000.&#x22;] },
      traceId: &#x22;00-07e9715cee7eefbb…-00&#x22;,
    },
    fix: &#x22;errors names each field at fault. To get past 10,000 results, narrow the search with filters.&#x22;,
  },
  {
    code: 404,
    name: &#x22;No such record&#x22;,
    cause: &#x22;The id in the path does not exist in that collection.&#x22;,
    body: {
      type: &#x22;https://tools.ietf.org/html/rfc9110#section-15.5.5&#x22;,
      title: &#x22;Not Found&#x22;,
      status: 404,
      traceId: &#x22;00-dec6defe42fccf66…-00&#x22;,
    },
    fix: &#x22;Check the id, and the collection: sd… and od… are datasets, cl… classifications, dr… reuses.&#x22;,
  },
]"
/>

## Data routes [#data-routes]

These responses apply to `/v1/data/organizations/…` and the legacy `/namespaces/…` routes.

<ErrorExplorer
  lang="en"
  errors="[
  {
    code: 400,
    name: &#x22;Invalid limit or offset&#x22;,
    cause: &#x22;In a query, limit is outside 1–100,000 (0, 100,001 and so on); in an export, limit is 0 or negative. Or offset is negative.&#x22;,
    body: {
      type: &#x22;https://tools.ietf.org/html/rfc9110#section-15.5.1&#x22;,
      title: &#x22;One or more validation errors occurred.&#x22;,
      status: 400,
      errors: { Limit: [&#x22;The field Limit must be between 1 and 100000.&#x22;], Offset: [&#x22;The field Offset must be between 0 and 2147483647.&#x22;] },
      traceId: &#x22;00-b63f7f14f2aa1d98…-00&#x22;,
    },
    fix: &#x22;errors names each field at fault. In a query, send limit from 1 to 100,000 (or omit it for 100 rows); for more rows, page with offset. An export has no upper bound: omit limit to export every matching row. offset starts at 0.&#x22;,
  },
  {
    code: 400,
    name: &#x22;Invalid table filter&#x22;,
    cause: &#x22;filter does not follow the filter grammar: a double == or spaces around =, an operator that does not exist (._gte, ._ne, ._in), or a column the table does not have.&#x22;,
    body: { error: &#x22;Invalid UAPI filter expression at line 1, column 25&#x22;, error_code: &#x22;INVALID_TABLE_QUERY&#x22; },
    fix: &#x22;Use one = for equality with no spaces (column='value'), one of the eight operators, and column names from the table schema. Retrying the same filter will not help.&#x22;,
  },
  {
    code: 400,
    name: &#x22;Query rejected by the engine&#x22;,
    cause: &#x22;select or sort names a column the table does not have, or a bare number is compared with a text column (time_period=2026).&#x22;,
    body: { error: &#x22;TrinoUserError(type=USER_ERROR, name=COLUMN_NOT_FOUND, message=\&#x22;line 1:39: Column 'nope' cannot be resolved\&#x22;, …)&#x22;, error_code: &#x22;TRINO_USER_ERROR&#x22; },
    fix: &#x22;Check column names against the table schema and put text values in quotes: time_period='2026'.&#x22;,
  },
  {
    code: 400,
    name: &#x22;Unsupported export format&#x22;,
    cause: &#x22;The format URL parameter is not one of ndjson, json, csv, parquet, xlsx.&#x22;,
    body: { error: &#x22;Invalid export format 'pdf'. Allowed values: json, ndjson, csv, parquet, xlsx.&#x22;, error_code: &#x22;INVALID_OUTPUT_FORMAT&#x22; },
    fix: &#x22;Pick one of the five formats.&#x22;,
  },
  {
    code: 400,
    name: &#x22;Wrong JSON type&#x22;,
    cause: &#x22;A body field has the wrong type — \&#x22;limit\&#x22;: null in a query, exclude_nulls as a string instead of a list — or the body is not JSON.&#x22;,
    body: {
      type: &#x22;https://tools.ietf.org/html/rfc9110#section-15.5.1&#x22;,
      title: &#x22;One or more validation errors occurred.&#x22;,
      status: 400,
      errors: { &#x22;$.limit&#x22;: [&#x22;The JSON value could not be converted to System.Int32. Path: $.limit | LineNumber: 0 | BytePositionInLine: 13.&#x22;] },
    },
    fix: &#x22;limit and offset are numbers (in a query, omit limit rather than send null; an export accepts null), select / filter / sort are strings, exclude_nulls is a list of strings.&#x22;,
  },
  {
    code: 404,
    name: &#x22;No such organization or table&#x22;,
    cause: &#x22;The organization id or the table name in the path does not exist.&#x22;,
    body: { message: &#x22;NoSuchTableException: Table does not exist: 188600177.nope&#x22;, error_code: &#x22;TABLE_NOT_FOUND&#x22; },
    fix: &#x22;List what exists with GET /v1/data/organizations and …/{id}/tables. error_code is NAMESPACE_NOT_FOUND or TABLE_NOT_FOUND; a missing file returns { message: null, error_code: null }.&#x22;,
  },
  {
    code: 502,
    name: &#x22;The data service failed&#x22;,
    cause: &#x22;The data service behind the API failed or sent an unexpected response. Mistakes in the request return 400, not 502.&#x22;,
    body: &#x22;error code: 502&#x22;,
    fix: &#x22;Retry after a pause, with a growing delay between attempts.&#x22;,
  },
  {
    code: 504,
    name: &#x22;Took too long&#x22;,
    cause: &#x22;The query ran out of time — usually a very deep offset or a large unfiltered scan.&#x22;,
    body: &#x22;error code: 504&#x22;,
    fix: &#x22;Filter more, or export the rows to a file instead of paging deep into the table. Retry with a pause.&#x22;,
  },
]"
/>

<Callout type="warn" title="A mistake in a query is a 400, not a 502">
  An invalid filter, an unknown column, or a `limit` or `offset` out of range returns `400` with a message and an `error_code` or field-level `errors`. Fix the request rather than retrying it. `502` means the data service itself failed; retry that after a pause.
</Callout>

## 403 from Python's `urllib` [#403-from-pythons-urllib]

The API's firewall refuses requests that carry the default user agent of Python's
built-in `urllib` (`Python-urllib/3.x`), answering `403 Forbidden`. `requests`,
`httpx`, R, curl and the rest are not affected. With `urllib`, set your own:

```python
req = urllib.request.Request(url, headers={"User-Agent": "my-app/1.0"})
```

## Handling errors [#handling-errors]

* Read the status first, then the body: JSON for most `4xx`, plain text or HTML for
  gateway `5xx`.
* Where there is an `error_code`, branch on it rather than on the message.
* Do not retry a `4xx`: fix the request first.
* Retry `502`, `503` and `504` with a growing pause.

## See also [#see-also]

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