# Reading data

> Read rows with the OData query options of the Fledge API, from filters and relations to paging and totals.

Every entity set is at the root of the API: `https://odata-api.fledge.nl/v2-8/<EntitySet>`. Find them, with their fields, in the [reference](https://docs.fledge.nl/en/api/reference).

## Administrations

One entity set holds the rows of all administrations. Rows of one administration have `administration_id` in their key.

- **Always filter on `administration_id`.** Without it, a request reads every administration your user has.
- Your administrations: `GET /Administrations?$select=administration_id,name`.

## One row

Address a row by its whole key. A key with more than one field names each part; text is in single quotes (double a quote inside it).

```http
GET /Articles(administration_id=1,article_id='10045')
GET /CountryCodes(31)
```

## Query options

| Option | Example | Notes |
| --- | --- | --- |
| `$select` | `$select=article_id,description_1` | Always use it: ask only for the fields you need. |
| `$filter` | `$filter=administration_id eq 1 and order_date ge 2026-01-01` | `eq ne gt ge lt le and or not in`, `contains`, `startswith`, `endswith`. |
| `$orderby` | `$orderby=order_date desc` |  |
| `$top`, `$skip` | `$top=100&$skip=100` | See paging below. |
| `$count` | `$count=true&$top=1` | Adds `@odata.count`: the number of rows that match. |
| `$expand` | `$expand=SalesOrderLines($select=sales_order_line_id,quantity;$top=50)` | Give an expanded set its own `$select`; a list also a `$top`. |
| `$apply` | `$apply=filter(administration_id eq 1)/groupby((debtor_id),aggregate($count as orders))` | Totals and counts computed by the API. Not together with `$expand`. |
| `$search` | `$search="w800" OR bout` | Finds the words in all text fields. Put a word with a digit in double quotes. |

**Enums.** A field with flags filters with `has`: `action_flags has FledgeDev.Enumerators.PurchaseOrderActionFlagsEnum'GOODS_RECEPTION'`. The reference lists the values per field.

**Empty values.** An empty text is `''`; an empty date is `null`. `contains` ignores case.

## Paging

| You send | You get |
| --- | --- |
| No `$top` | 50 rows and `@odata.nextLink`: follow it for the next page until it is gone. |
| `Prefer: odata.maxpagesize=200` header | Pages of 200 rows (at most 1000), with `@odata.nextLink`. |
| `$top=100` | At most 100 rows, no `@odata.nextLink`. Get the next page with `$skip`, ordered on the key. |

An expanded list is paged too: it then has its own `<Navigation>@odata.nextLink`.

## Totals instead of rows

Let the API count and add up. The number of orders per customer this year is one row per customer, not every order:

```http
GET /SalesOrderHeaders?$apply=filter(administration_id eq 1 and order_date ge 2026-01-01)
    /groupby((debtor_id),aggregate($count as orders))
```

Sums work the same way: `aggregate(<field> with sum as total)`.

Put the conditions inside `$apply` with `filter(…)`, before `groupby`.

## Administration settings

Some answers depend on how an administration is set up. Read a setting by its name:

```http
GET /Administrations(1)/Setting(name='DEBTOR_INITIAL')
```

## Known limitations

As of version 2.8, these requests fail with an error. Write them another way:

| Request | Instead |
| --- | --- |
| `not (order_date ge 2026-01-01)` around `lt le gt ge` | The opposite comparison: `order_date lt 2026-01-01` |
| `countdistinct`, `tolower`, `toupper`, `now()` | Group first, or compare without changing case (`contains` ignores case) |
| `$search` together with `$apply` | `$filter` with `contains` in the `$apply` |
| `$top` with a `groupby` on two or more fields, or two or more aggregates | Leave out `$top` |
| An unknown field in `$filter` | Check the field in the reference: it gives `500`, not `400` |

---

Source: https://docs.fledge.nl/en/api/reading-data
