Metrics

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

Endpoints

GET
GET
POST
GET
PATCH
DELETE
POST
GET
POST
POST
GET
POST
POST

Retrieve metrics query counts

How often queries read each metric of the team. A metric that no query reads is not in the list.

Required API key scopes

metrics:read

Query parameters

  • days
    integer
    Default: 30
  • limit
    integer
    Default: 100

Response


Example request

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

Example response

Status 200
RESPONSE
{
"results": [
{
"metric_name": "string",
"query_count": 0,
"last_queried_at": "2019-08-24T14:15:22Z"
}
]
}

Retrieve metrics query counts

How often queries read each metric of the team. A metric that no query reads is not in the list.

Required API key scopes

metrics:read

Query parameters

  • days
    integer
    Default: 30
  • limit
    integer
    Default: 100

Response


Example request

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

Example response

Status 200
RESPONSE
{
"results": [
{
"metric_name": "string",
"query_count": 0,
"last_queried_at": "2019-08-24T14:15:22Z"
}
]
}

List all metrics recording rules

The project's recording rules, by metric name.

Required API key scopes

metrics:read

Example request

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

Example response

Status 200
RESPONSE
{
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"metric_name": "string",
"query": "string",
"description": "",
"enabled": true,
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z",
"last_evaluated_at": "2019-08-24T14:15:22Z",
"last_series_count": 0,
"last_error": "string"
}

Create metrics recording rules

Create a recording rule. It writes its first result within about a minute.

Required API key scopes

metrics:write

Request parameters

  • metric_name
    string
  • query
    string
  • description
    string
    Default:
  • enabled
    boolean
    Default: true

Response


Example request

POST /api/projects/:project_id/metrics/recording_rules
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/recording_rules/\
-d metric_name="string",\
-d query="string"

Example response

Status 201
RESPONSE
{
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"metric_name": "string",
"query": "string",
"description": "",
"enabled": true,
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z",
"last_evaluated_at": "2019-08-24T14:15:22Z",
"last_series_count": 0,
"last_error": "string"
}
Status 400 The rule is not valid, or the project has too many rules.

Retrieve metrics recording rules

Recording rules evaluate a PromQL query every minute and write its result into this project's metrics under a new metric name, so dashboards and alerts can read the stored result instead of the query.

Required API key scopes

metrics:read

Path parameters

  • id
    string

Response


Example request

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

Example response

Status 200
RESPONSE
{
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"metric_name": "string",
"query": "string",
"description": "",
"enabled": true,
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z",
"last_evaluated_at": "2019-08-24T14:15:22Z",
"last_series_count": 0,
"last_error": "string"
}

Update metrics recording rules

Change a rule's query, description or enabled state. The metric name cannot change.

Required API key scopes

metrics:write

Path parameters

  • id
    string

Request parameters

  • query
    string
  • description
    string
  • enabled
    boolean

Response


Example request

PATCH /api/projects/:project_id/metrics/recording_rules/:id
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl -X PATCH \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/metrics/recording_rules/:id/\
-d query="string"

Example response

Status 200
RESPONSE
{
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"metric_name": "string",
"query": "string",
"description": "",
"enabled": true,
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z",
"last_evaluated_at": "2019-08-24T14:15:22Z",
"last_series_count": 0,
"last_error": "string"
}
Status 400 The edit is not valid, or it tries to change the metric name.

Delete metrics recording rules

Delete a rule. The series it already wrote stay until the project's metrics retention removes them.

Required API key scopes

metrics:write

Path parameters

  • id
    string

Example request

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

Example response

Status 204 No response body

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.

Create metrics suggested dashboards dismiss

Remove the suggestion from this project's suggested dashboards, for every user of the project. The suggestion does not come back. A dashboard that was created from it stays. A second call does nothing.

Required API key scopes

metrics:write

Path parameters

  • id
    string

Example request

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

Example response

Status 204 The suggestion is dismissed.
Status 404 The project has no such suggestion.

Retrieve metrics values

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

Required API key scopes

metrics:read

Query parameters

  • first_seen
    boolean
    Default: false
  • fold_histograms
    boolean
    Default: false
  • limit
    integer
    Default: 100
  • match
    string
    Default: substring
    One of: "substring""prefix""regex"
  • series_stats
    boolean
    Default: false
  • service
    string
  • sparklines
    boolean
    Default: true
  • 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
],
"first_seen": "2019-08-24T14:15:22Z",
"series_count": 0,
"tag_key_count": 0,
"classic_histogram": {
"base_name": "string",
"bucket": "string",
"sum": "string",
"count": "string"
}
}
]
}

Retrieve metrics values

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

Required API key scopes

metrics:read

Query parameters

  • first_seen
    boolean
    Default: false
  • fold_histograms
    boolean
    Default: false
  • limit
    integer
    Default: 100
  • match
    string
    Default: substring
    One of: "substring""prefix""regex"
  • series_stats
    boolean
    Default: false
  • service
    string
  • sparklines
    boolean
    Default: true
  • 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
],
"first_seen": "2019-08-24T14:15:22Z",
"series_count": 0,
"tag_key_count": 0,
"classic_histogram": {
"base_name": "string",
"bucket": "string",
"sum": "string",
"count": "string"
}
}
]
}

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
],
"first_seen": "2019-08-24T14:15:22Z",
"series_count": 0,
"tag_key_count": 0,
"classic_histogram": {
"base_name": "string",
"bucket": "string",
"sum": "string",
"count": "string"
}
}
]
}

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
],
"first_seen": "2019-08-24T14:15:22Z",
"series_count": 0,
"tag_key_count": 0,
"classic_histogram": {
"base_name": "string",
"bucket": "string",
"sum": "string",
"count": "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"
]
}

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