---
title: "POST /api/projects/{project_id}/metrics/variable_options/"
method: POST
path: "/api/projects/{project_id}/metrics/variable_options/"
tags: ["metrics", "metrics"]
---

# POST /api/projects/{project_id}/metrics/variable_options/

`POST /api/projects/{project_id}/metrics/variable_options/`

## Request

- Base URL: `https://us.posthog.com`
- URL: `https://us.posthog.com/api/projects/{project_id}/metrics/variable_options/`
- Auth: HTTP bearer

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

## Path parameters

- `project_id` string, required

## Request body

- MetricVariableOptionsRequest
  - `source` 'custom' | 'promql' | 'sql' | 'textbox', required: * `custom` - custom * `promql` - promql * `sql` - sql * `textbox` - textbox
  - `query` string, nullable: The options query when `source` is `promql` or `sql`. It can refer to other variables as `$name`. PromQL supports label_values(label), label_values(selector, label), label_names(), metrics(regex) and query_result(expr). SQL returns the options in its first column.
  - `customValues` string[], nullable: The options when `source` is `custom`.
  - `regex` string, nullable: A regex that filters the options of a query, as `pattern` or `/pattern/flags`. With a capture group, each option is its first group. An invalid regex is rejected before any query runs.
  - `variables` MetricVariableSelection[]: The current selection of the other dashboard variables that the query can refer to.
    - `name` string, required: Variable name. Queries refer to it as `$name`.
    - `values` string[], required: The selected values. When `all` is true, the options that All stands for.
    - `all` boolean: True when the variable is set to All.
    - `allValue` string, nullable: The text that All puts in a PromQL query. `.*` when it is empty.
  - `dateFrom` string, nullable: Start of the window that options come from, as in a dashboard date filter: ISO 8601 or a relative date such as '-7d'. Defaults to 24 hours ago.
  - `dateTo` string, nullable: End of the window that options come from, in the same format as dateFrom. Defaults to now.

## Response `200`

- MetricVariableOptionsResponse
  - `results` string[], required: The options of the variable, at most 1,000.

## Changes

> 53 revisions in range; 1 not diffed.

- **2026-10-19** `596bdf1a6636`: 1 info
  - endpoint added

[Operation history](https://skmtc.dev/posthog/apis/posthog-api/changes/api/projects/:project_id/metrics/variable_options/post.md)

---

[API](https://skmtc.dev/posthog/apis/posthog-api.md) · [All operations](https://skmtc.dev/posthog/apis/posthog-api/llms.txt) · [OpenAPI document](https://skmtc.dev/posthog/apis/posthog-api/revisions/993f70ab941b?raw)
