# Data Endpoints

> Serve filter results to your product through an API. Configure a query in the UI, then call it with a single POST and get back the fields you chose, as JSON or CSV.

Part of [Real-Time Metrics](https://aggregations.io/real-time-metrics.md). Full reference: [Endpoints docs](https://aggregations.io/docs/data-endpoints.md).

## What an Endpoint stores

The [Metrics API](https://aggregations.io/real-time-metrics/api.md) exposes every option, but most products repeat the same few queries. An Endpoint stores that configuration so your code doesn't have to:

- **Filter:** any filter you've already built.
- **Timing:** a lookback total (for example the last 24 hours, with an optional offset) or a time series.
- **Groupings:** return every value, a fixed list, roll them up, or let the caller choose at query time.
- **Fields:** named calculations to return, then sorting and limits.

## Calling an Endpoint

```bash
curl -X POST https://app.aggregations.io/api/v1/data/{id} \
  -H "x-api-token: $READ_KEY" \
  -d '{"groupingFilters": {"@.item_id": ["sku_123"]}}'
```

```json
[
  { "groupings": { "$.device.type": "ios" },
    "fields": { "L24_Total": 26140, "L24_Uniques": 5120, "L24_yday_total": 24480 } }
]
```

Send `"format": "CSV"` for a header row plus your data. Requests use a read-only key.

## One filter, many Endpoints

Any number of Endpoints can read from the same filter, each with its own timing, groupings, fields and sorting. From one "Impressions" filter (grouped by item, device and customer; hourly; counts, distinct viewers, duration percentiles):

| Endpoint | Used for | Settings |
| --- | --- | --- |
| `customer-usage` | Usage page for each customer | 30-day lookback, `@.customer_id` at query time |
| `top-items` | Trending list | 24-hour lookback, all items, sorted by impressions, limit 10 |
| `impressions-hourly` | Admin chart | hourly time series over 7 days, by device |
| `weekly-export` | Finance spreadsheet | weekly time series over 12 weeks, CSV |

## Top N within each group

Sorting and limits work across nested groupings. Group by team and player, sort by score, and keep the top 3 players in each team with an overall row limit. One request returns a leaderboard for every team; the same works for top products per category or top pages per customer. See [grouping limits](https://aggregations.io/docs/data-endpoints.md#grouping-limits).

## Changing an Endpoint without a release

Say an in-app tile shows impressions for the last 24 hours and you want the last 7 days with the change from the week before. Change the lookback to 7 days and add a field with a 7-day offset in the UI; the app's request stays the same and gets the new numbers on its next call. Filter edits that would break an Endpoint's fields are blocked and flagged.

## Common uses

- Customer-facing usage pages, with a query-time grouping so each request only returns that customer's numbers.
- KPI tiles (lookbacks) and the charts beside them (time series).
- Leaderboards.
- Spreadsheets and BI tools via CSV.
