# REST API

> JSON in, metrics out. Define a metric once in the UI, query it over HTTP from anything, and send events as the JSON you already produce.

Part of [Real-Time Metrics](https://aggregations.io/real-time-metrics.md). Full reference: [Metrics API docs](https://aggregations.io/docs/metrics/metrics-api.md), [Posting events](https://aggregations.io/docs/ingesting-data/posting-events.md).

## Metrics API

A filter holds the expensive decisions: which events count, the groupings, the interval, and up to 10 aggregations. The questions come later: each request picks an aggregation and calculation and decides how to treat each grouping, which percentile to read, how many groups to keep and how wide the intervals are. None of that needs a new filter.

1. `GET https://app.aggregations.io/api/v1/filter-definitions` lists your filters with their groupings and aggregation IDs.
2. `POST https://app.aggregations.io/api/v1/metrics/results` returns one row per interval and group, using your grouping aliases.

```json
{
  "filterId": "6f1c…",
  "aggregationId": 1,
  "calculation": "APPROX_COUNT_DISTINCT",
  "startTime": "2026-11-14T09:00:00Z",
  "endTime": "2026-11-14T10:00:00Z",
  "groupingFilters": [
    { "grouping": "@.device.type", "filters": ["ios"], "returnGroupingValues": false }
  ],
  "recalculatedInterval": { "type": "MINUTE", "frequency": 15 }
}
```

Per request you can set:

- **Grouping filters:** keep every value, keep a list of values, filter without returning the key, or roll a grouping up with `["$__agg"]`.
- **Top or bottom N** groups per interval.
- **Percentile** at query time (percentiles are stored as t-digests, so p50, p95 or p99 is a parameter).
- **Rollups** to any wider interval (minutes to hours, days or months).
- **Incomplete intervals**: include or leave out the interval still filling.

Examples from one filter on app opens (grouped by device and version; users as distinct count, session length as average and percentiles): daily active users on iOS, unique users across all platforms (rolled up, so someone on iOS and Android counts once), p95 session length by version, and the 5 busiest versions each hour.

The same API powers the [Grafana plugin](https://aggregations.io/real-time-metrics/grafana.md). For a query your app repeats, a [Data Endpoint](https://aggregations.io/real-time-metrics/data-endpoints.md) stores it.

## Ingest API

POST a batch of JSON events to your ingest URL with a key that has write permission. No SDK, no tracking plan.

```bash
curl https://ingest.aggregations.io/abc12345 \
  -H 'Content-Type: application/json' \
  -H 'x-api-token: $WRITE_KEY' \
  -d '[{"eventName": "appOpen", "userId": "u_8f2c41", "device": {"type": "ios"}, "app": {"version": "3.4.0"}}]'
```

- Up to 1 MB per request and 1,000 requests a second by default.
- Use the time an event is received, or a timestamp property in your events for backfills and delayed sources.
- Errors are plain HTTP: `400` for bad payloads, `401` for keys, `429` for limits.
- Four payload formats: a JSON array, newline-delimited JSON, an object with an events array at a path you set, or a single object (for webhooks that can't batch).
- Existing pipelines connect directly: Segment, webhooks, Amazon Kinesis (Firehose) and Confluent Cloud (Kafka HTTP sink). See [integrations](https://aggregations.io/docs/ingesting-data/integrations.md).

## Keep your event structure

Filters, groupings and fields point at properties with JPath, so nested objects, arrays and events from different sources work as they are. A backend event with `@.order.total` and a Segment event with `@.properties.revenue` can both be aggregated without renaming or flattening anything. Raw events aren't stored, so extra properties cost nothing.

## Keys and limits

- Metrics calls need a key with read permission. Write-only keys can ship in mobile and web apps because they can't read anything back.
- The Metrics API allows 150 requests every 10 seconds per organization.
