# Get an analytics time series

> Source: https://truto.one/docs/api-reference/admin/analytics/timeseries/

`GET /analytics/timeseries`

Resource: **Analytics**

**One metric per day (or per hour for up to 7 days)**, read live from the logs and cached for 6 hours. Optionally grouped by a dimension (top 10 groups, the rest summed as `__other__` for additive metrics) and filtered with `filter[<dimension>]=<value>`. The range is clamped to the 90-day window ending today; an hour later today is `null`, not `0`.

## Query parameters

- **`environment_id`** _(string, required)_
  The environment to report on. The caller must belong to it.
- **`metric`** _(string, required)_
- **`from`** _(string)_
  Defaults to 30 days before `to`.
- **`to`** _(string)_
  Defaults to today.
- **`granularity`** _(string)_
  `hour` covers at most 7 days, for a metric with hourly data (see `GET /analytics/metrics`).
  Allowed: `day`, `hour`
- **`group_by`** _(string)_
- **`filter`** _(object)_

## Response body

- **`environment_id`** _(string)_
- **`metric`** _(string)_
- **`unit`** _(string)_
- **`kind`** _(string)_
- **`granularity`** _(string)_
- **`from`** _(string)_
- **`to`** _(string)_
- **`buckets`** _(array<string>)_
- **`series`** _(array<object>)_
  - **`key`** _(string)_
  - **`values`** _(array<number>)_
  - **`total`** _(number)_

## Errors

| Status | Description |
| :----- | :---------- |
| `400` | Unknown metric, dimension, filter or query parameter; a dimension or filter the metric does not support; a value with control characters; a malformed date; or a range outside the window |
| `403` | Forbidden if the caller cannot reach the environment (an API token reaches its own environment only), or uses an integrated-account or tenant token |
| `429` | More uncached analytics reads for this environment than the per-minute limit allows. Retry after the `Retry-After` header (60 seconds). Cached responses are not limited. |
| `502` | The logs could not be read. The response carries a generic message; retry in a minute. |

## Code examples

### curl

```bash
curl -X GET 'https://api.truto.one/analytics/timeseries' \
  -H 'Authorization: Bearer <your_api_token>' \
  -H 'Content-Type: application/json'
```

### JavaScript

```javascript
const response = await fetch('https://api.truto.one/analytics/timeseries', {
  method: 'GET',
  headers: {
    'Authorization': 'Bearer <your_api_token>',
    'Content-Type': 'application/json',
  },
});

const data = await response.json();
console.log(data);
```

### Python

```python
import requests

url = "https://api.truto.one/analytics/timeseries"
headers = {
    "Authorization": "Bearer <your_api_token>",
    "Content-Type": "application/json",
}
params = {
}

response = requests.get(url, headers=headers, params=params)
print(response.json())
```
