---
title: "Metric"
method: POST
path: "/api/metric"
tags: ["Metric"]
---

# Metric

`POST /api/metric`

## Request

- Base URL: `https://api.lytics.io`
- URL: `https://api.lytics.io/api/metric`
- Auth: API key in header `Authorization`

Fetch metrics by providing the arguments in the request body

```sh
# Example of segment-size metrics
curl -s -XPOST "$LIOAPI/api/metric" \
    -H 'Content-type: application/json' \
    -H "Authorization: $LIOKEY" \
    -d '{
            "dimension": "segsize",
            "dimension_id": "abc123",
            "dimension_type": "size",
            "interval": "2h",
            "aggregation": "max",
            "start_date": "now-5d",
            "end_date": "now",
            "smooth": true
    }' | jq '.'


# Example request of data collected from the default and email stream
curl -s -XPOST "$LIOAPI/api/metric" \
    -H "Content-type: application/json" \
    -H "Authorization: $LIOKEY" \
    -d '[{
            "dimension": "stream",
            "dimension_id": "default",
            "dimension_type": "size",
            "interval": "1h",
            "aggregation": "sum",
            "start_date": "now-1w",
            "end_date": "now"
        },
        {
            "dimension": "stream",
            "dimension_id": "email",
            "dimension_type": "size",
            "interval": "1h",
            "aggregation": "sum",
            "start_date": "now-2w",
            "end_date": "now"
        }]' | jq '.'

```

## Query parameters

- `account_id` string

## Request body

- object
  - `dimension` string: Value of supported dimension (segment, experience, stream, etc)
  - `dimension_id` string: ID for the specific item within dimension such as a segment ID. Tip: If the type is a segment you can use all_segments as the dimension id to get all segments for the account.
  - `dimension_type` string: Type of metric to be returned (size, converted, etc)
  - `interval` string: Duration to roll-up metrics (2h for roll-up into two-hour buckets). Intervals smaller than two hours are not recommended.
  - `aggregation` string: Aggregation to apply to metrics (sum, max, min)
  - `smooth` boolean: Smooth metrics using a moving-average function
  - `include_empty_rows` boolean: Passing true will include zero values in the response for every interval whether metrics were logged during that period or not.
  - `start_date` string: Fetch metrics after this date; both dates and relative-dates are supported
  - `end_date` string: Fetch metrics before this date; both dates and relative-dates are supported

## Response `200`

OK

- MetricModel
  - `data` object[]
    - `name` string
    - `dimension` string
    - `dimension_id` string
    - `dimension_type` string
    - `range` string
    - `aggregation` string
    - `interval` string
    - `is_cached` boolean
    - `values` object[]
      - `value` number, required
      - `ts` string, required
  - `message` string
  - `status` number

---

[API](https://skmtc.dev/lytics/apis/v1-lytics-api.md) - [All operations](https://skmtc.dev/lytics/apis/v1-lytics-api/llms.txt) - [OpenAPI document](https://skmtc.dev/lytics/apis/v1-lytics-api/revisions/339fd1d88486?raw)
