Metrics

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

Endpoints

POST
GET
POST
GET
POST
POST

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"
}
}
]
}

List all metrics suggested dashboards

Dashboards from the metrics dashboard bank that suit the metrics this project sends, best fit first.

Required API key scopes

metrics:read

Example request

GET /api/projects/:project_id/metrics/suggested_dashboards
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/suggested_dashboards/

Example response

Status 200
RESPONSE
{
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"template_id": "c6d67e98-83ea-49f0-8812-e4abae2b68bc",
"name": "string",
"description": "string",
"reason": "string",
"panel_count": 0,
"matched_metric_count": 0,
"coverage": 0.1,
"dashboard_id": 0
}

Create metrics suggested dashboards dashboard

Create the suggested dashboard in this project, with only the charts whose metrics the project sends. A second call returns the dashboard that the first one created.

Required API key scopes

metrics:readdashboard:writeinsight:write

Path parameters

  • id
    string

Response


Example request

POST /api/projects/:project_id/metrics/suggested_dashboards/:id/dashboard
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/suggested_dashboards/:id/dashboard/

Example response

Status 201
RESPONSE
{
"dashboard_id": 0
}
Status 400 The project no longer sends the metrics of this dashboard.

Retrieve metrics values

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

Required API key scopes

metrics:read

Query parameters

  • limit
    integer
    Default: 100
  • service
    string
  • 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",
"unit": "string",
"last_seen": "2019-08-24T14:15:22Z",
"sparkline": [
0.1
]
}
]
}

Retrieve metrics values

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

Required API key scopes

metrics:read

Query parameters

  • limit
    integer
    Default: 100
  • service
    string
  • 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",
"unit": "string",
"last_seen": "2019-08-24T14:15:22Z",
"sparkline": [
0.1
]
}
]
}

Create metrics values

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

Required API key scopes

metrics:read

Request parameters

  • value
    string
    Default:
  • limit
    integer
    Default: 100
  • service
    string
  • names
    array

Response


Example request

POST /api/projects/:project_id/metrics/values
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/values/\
-d names="array"

Example response

Status 200
RESPONSE
{
"results": [
{
"name": "string",
"metric_type": "string",
"unit": "string",
"last_seen": "2019-08-24T14:15:22Z",
"sparkline": [
0.1
]
}
]
}

Create metrics values

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

Required API key scopes

metrics:read

Request parameters

  • value
    string
    Default:
  • limit
    integer
    Default: 100
  • service
    string
  • names
    array

Response


Example request

POST /api/projects/:project_id/metrics/values
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/values/\
-d names="array"

Example response

Status 200
RESPONSE
{
"results": [
{
"name": "string",
"metric_type": "string",
"unit": "string",
"last_seen": "2019-08-24T14:15:22Z",
"sparkline": [
0.1
]
}
]
}

Create metrics variable options

The options of one dashboard variable, for the variable selects on dashboards.

Required API key scopes

metrics:read

Request parameters

  • source
  • query
    string | null
  • customValues
    array | null
  • regex
    string | null
  • variables
    Click to open
    array
  • dateFrom
    string | null
  • dateTo
    string | null

Response


Example request

POST /api/projects/:project_id/metrics/variable_options
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/variable_options/\
-d source=undefined

Example response

Status 200
RESPONSE
{
"results": [
"string"
]
}

Create metrics variable options

The options of one dashboard variable, for the variable selects on dashboards.

Required API key scopes

metrics:read

Request parameters

  • source
  • query
    string | null
  • customValues
    array | null
  • regex
    string | null
  • variables
    Click to open
    array
  • dateFrom
    string | null
  • dateTo
    string | null

Response


Example request

POST /api/projects/:project_id/metrics/variable_options
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/variable_options/\
-d source=undefined

Example response

Status 200
RESPONSE
{
"results": [
"string"
]
}