Metrics

For instructions on how to authenticate to use this endpoint, see API overview.

Endpoints

GET
GET
POST
GET
POST
POST
GET

Retrieve metrics attribute values

Observed values for one metric attribute key, most frequent first. Backs the filter bar's value autocomplete.

Required API key scopes

metrics:read

Query parameters

  • dateFrom
    stringnull
  • dateTo
    stringnull
  • key
    string
  • limit
    integer
    Default: 100
  • value
    string
    Default:

Response


Example request

GET /api/projects/:project_id/metrics/attribute_values
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/metrics/attribute_values/

Example response

Status 200
RESPONSE
{
"results": [
{
"id": "string",
"name": "string",
"count": 0
}
]
}

Retrieve metrics attribute values

Observed values for one metric attribute key, most frequent first. Backs the filter bar's value autocomplete.

Required API key scopes

metrics:read

Query parameters

  • dateFrom
    stringnull
  • dateTo
    stringnull
  • key
    string
  • limit
    integer
    Default: 100
  • value
    string
    Default:

Response


Example request

GET /api/projects/:project_id/metrics/attribute_values
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/metrics/attribute_values/

Example response

Status 200
RESPONSE
{
"results": [
{
"id": "string",
"name": "string",
"count": 0
}
]
}

Retrieve metrics attributes

Distinct attribute keys seen on the team's metrics (datapoint and resource attributes merged), most frequent first. Backs the filter bar's key autocomplete.

Required API key scopes

metrics:read

Query parameters

  • dateFrom
    stringnull
  • dateTo
    stringnull
  • limit
    integer
    Default: 100
  • search
    string
    Default:

Response


Example request

GET /api/projects/:project_id/metrics/attributes
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/metrics/attributes/

Example response

Status 200
RESPONSE
{
"results": [
{
"name": "string"
}
],
"count": 0
}

Retrieve metrics attributes

Distinct attribute keys seen on the team's metrics (datapoint and resource attributes merged), most frequent first. Backs the filter bar's key autocomplete.

Required API key scopes

metrics:read

Query parameters

  • dateFrom
    stringnull
  • dateTo
    stringnull
  • limit
    integer
    Default: 100
  • search
    string
    Default:

Response


Example request

GET /api/projects/:project_id/metrics/attributes
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/metrics/attributes/

Example response

Status 200
RESPONSE
{
"results": [
{
"name": "string"
}
],
"count": 0
}

Create metrics characterize

Characterize a metric anomaly: compare an anomaly window against a baseline, find the onset, and rank which label values moved.

Required API key scopes

metrics:read

Request parameters

  • query

Response


Example request

POST /api/projects/:project_id/metrics/characterize
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl
-H 'Content-Type: application/json'\
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/metrics/characterize/\
-d query=undefined

Example response

Status 200
RESPONSE
{
"metric_name": "string",
"aggregation": "string",
"interval": "string",
"baseline_from": "string",
"baseline_to": "string",
"anomaly_from": "string",
"anomaly_to": "string",
"baseline_mean": 0.1,
"baseline_stddev": 0.1,
"anomaly_mean": 0.1,
"anomaly_peak": 0.1,
"change_ratio": 0.1,
"direction": "up",
"onset_time": "string",
"top_movers": [
{
"key": "string",
"label": "string",
"baseline_value": 0.1,
"anomaly_value": 0.1,
"change_ratio": 0.1
}
],
"series": {
"labels": {
"property1": "string",
"property2": "string"
},
"points": [
{
"time": "string",
"value": 0
}
],
"metric_name": "string",
"clause": "string"
}
}

Create metrics characterize

Characterize a metric anomaly: compare an anomaly window against a baseline, find the onset, and rank which label values moved.

Required API key scopes

metrics:read

Request parameters

  • query

Response


Example request

POST /api/projects/:project_id/metrics/characterize
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl
-H 'Content-Type: application/json'\
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/metrics/characterize/\
-d query=undefined

Example response

Status 200
RESPONSE
{
"metric_name": "string",
"aggregation": "string",
"interval": "string",
"baseline_from": "string",
"baseline_to": "string",
"anomaly_from": "string",
"anomaly_to": "string",
"baseline_mean": 0.1,
"baseline_stddev": 0.1,
"anomaly_mean": 0.1,
"anomaly_peak": 0.1,
"change_ratio": 0.1,
"direction": "up",
"onset_time": "string",
"top_movers": [
{
"key": "string",
"label": "string",
"baseline_value": 0.1,
"anomaly_value": 0.1,
"change_ratio": 0.1
}
],
"series": {
"labels": {
"property1": "string",
"property2": "string"
},
"points": [
{
"time": "string",
"value": 0
}
],
"metric_name": "string",
"clause": "string"
}
}

Retrieve metrics has metrics

Required API key scopes

metrics:read

Response


Example request

GET /api/projects/:project_id/metrics/has_metrics
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/metrics/has_metrics/

Example response

Status 200
RESPONSE
{
"hasMetrics": true
}

Retrieve metrics has metrics

Required API key scopes

metrics:read

Response


Example request

GET /api/projects/:project_id/metrics/has_metrics
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/metrics/has_metrics/

Example response

Status 200
RESPONSE
{
"hasMetrics": true
}

Create metrics query

Required API key scopes

metrics:read

Request parameters

  • query

Response


Example request

POST /api/projects/:project_id/metrics/query
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl
-H 'Content-Type: application/json'\
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/metrics/query/\
-d query=undefined

Example response

Status 200
RESPONSE
{
"results": [
{
"labels": {
"property1": "string",
"property2": "string"
},
"points": [
{
"time": "string",
"value": 0
}
],
"metric_name": "string",
"clause": "string"
}
]
}

Create metrics query

Required API key scopes

metrics:read

Request parameters

  • query

Response


Example request

POST /api/projects/:project_id/metrics/query
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl
-H 'Content-Type: application/json'\
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/metrics/query/\
-d query=undefined

Example response

Status 200
RESPONSE
{
"results": [
{
"labels": {
"property1": "string",
"property2": "string"
},
"points": [
{
"time": "string",
"value": 0
}
],
"metric_name": "string",
"clause": "string"
}
]
}

Create metrics samples

Raw individual emissions for a metric (the events model), newest first — backs the Samples view and the metric->trace pivot.

Required API key scopes

metrics:read

Request parameters

  • query

Response


Example request

POST /api/projects/:project_id/metrics/samples
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl
-H 'Content-Type: application/json'\
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/metrics/samples/\
-d query=undefined

Example response

Status 200
RESPONSE
{
"results": [
{
"timestamp": "string",
"metric_name": "string",
"metric_type": "string",
"value": 0.1,
"count": 0,
"unit": "string",
"aggregation_temporality": "string",
"is_monotonic": true,
"service_name": "string",
"trace_id": "string",
"span_id": "string",
"attributes": {
"property1": "string",
"property2": "string"
},
"resource_attributes": {
"property1": "string",
"property2": "string"
}
}
]
}

Create metrics samples

Raw individual emissions for a metric (the events model), newest first — backs the Samples view and the metric->trace pivot.

Required API key scopes

metrics:read

Request parameters

  • query

Response


Example request

POST /api/projects/:project_id/metrics/samples
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl
-H 'Content-Type: application/json'\
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/metrics/samples/\
-d query=undefined

Example response

Status 200
RESPONSE
{
"results": [
{
"timestamp": "string",
"metric_name": "string",
"metric_type": "string",
"value": 0.1,
"count": 0,
"unit": "string",
"aggregation_temporality": "string",
"is_monotonic": true,
"service_name": "string",
"trace_id": "string",
"span_id": "string",
"attributes": {
"property1": "string",
"property2": "string"
},
"resource_attributes": {
"property1": "string",
"property2": "string"
}
}
]
}

Retrieve metrics values

Distinct metric names for the team. Backs the picker UI.

Required API key scopes

metrics:read

Query parameters

  • limit
    integer
    Default: 100
  • value
    string
    Default:

Response


Example request

GET /api/projects/:project_id/metrics/values
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/metrics/values/

Example response

Status 200
RESPONSE
{
"results": [
{
"name": "string",
"metric_type": "string"
}
]
}

Retrieve metrics values

Distinct metric names for the team. Backs the picker UI.

Required API key scopes

metrics:read

Query parameters

  • limit
    integer
    Default: 100
  • value
    string
    Default:

Response


Example request

GET /api/projects/:project_id/metrics/values
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/metrics/values/

Example response

Status 200
RESPONSE
{
"results": [
{
"name": "string",
"metric_type": "string"
}
]
}

Community questions