Metrics

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

Endpoints

GET
POST
POST
GET

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

Questions about this page? or post a community question.