> ## Documentation Index
> Fetch the complete documentation index at: https://85b42a7-productmetrics.manicule.dev/docs/llms.txt
> Use this file to discover all available pages before exploring further.
> For every page in one file, fetch https://85b42a7-productmetrics.manicule.dev/docs/llms-full.txt (large).
> To search and read these docs as tools, connect the MCP server at https://85b42a7-productmetrics.manicule.dev/docs/api/mcp.
> Every agent surface: https://85b42a7-productmetrics.manicule.dev/docs/.well-known/llms-manifest.json

# Query the lake (/docs/api/store-data/data-query)

<!-- agent-signals: reading_time_min: 3 · est_tokens: 1497 · updated: 2026-11-16 -->
Related: [Get analytics status](/docs/api/store-data/analytics-get-status.md), [Get an insight card](/docs/api/store-data/insights-get.md), [Get inventory state](/docs/api/store-data/inventory-get-state.md), [Check orders are available](/docs/api/store-data/orders-get-availability.md), [Get an order](/docs/api/store-data/orders-get.md), [List orders](/docs/api/store-data/orders-list.md)

> Runs ONE read-only SQL SELECT over this property's own lake tables (the tenant scope is applied for you; no comments, UNION or writes) and returns at most max_rows rows (1–500, default 100) with the data age per source.

`POST https://prod-backend.productmetrics.io/api/public/v1/properties/{propertyId}/query`

**Scope** `read` · **Access** Read only · **Operation id** `data.query`

## Try it

`productmetrics` runs after `productmetrics login`; curl needs `PM_TOKEN` (see [Authentication](/docs/api/overview#authentication)). Set `$PROPERTY_ID` first.



**productmetrics CLI:**

```bash
productmetrics data query \
  --property-id $PROPERTY_ID \
  --sql 'SELECT event_date, COUNT(*) AS products FROM daily_product_journey GROUP BY event_date ORDER BY event_date DESC LIMIT 2' \
  --json
```

**curl:**

```bash
curl -X POST "https://prod-backend.productmetrics.io/api/public/v1/properties/$PROPERTY_ID/query" \
  -H "Authorization: Bearer $PM_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "sql": "SELECT event_date, COUNT(*) AS products FROM daily_product_journey GROUP BY event_date ORDER BY event_date DESC LIMIT 2"
  }'
```

## Response



API response (200):

```json
{
  "data": {
    "columns": [
      "event_date",
      "products"
    ],
    "rows": [
      [
        "2026-11-12",
        1840
      ],
      [
        "2026-11-11",
        1836
      ]
    ],
    "truncated": false,
    "dataAsOf": {
      "google_ads": "2026-11-12",
      "merchant_center": "2026-11-13"
    }
  },
  "request_id": "req_01JD85CWTYRWYFND5RHXQW3TSZ"
}
```

**CLI output:** `productmetrics data query --json` prints `{ "ok": true, "data": …, "request_id": "…" }` with the same `data`.

## Before you call

It is slow and rate-limited (30 per person and 120 per property per hour, shared with the Product Metrics assistant), and needs Pro. Prefer the specific read operations ([`orders.list`](/docs/api/store-data/orders-list), store.get_health\_\*, [`inventory.get_state`](/docs/api/store-data/inventory-get-state)) whenever one answers the question; use this only for what they cannot. A refused or failing query answers 400 with an instruction to fix the SQL; 429 carries Retry-After.

## Path parameters

| Name         | Type          | Description                                                                                                         |
| ------------ | ------------- | ------------------------------------------------------------------------------------------------------------------- |
| `propertyId` | string (uuid) | The property id, from `productmetrics whoami` or [`properties.list`](/docs/api/account/properties-list) (`property_id`). |

## Body

| Name       | Type    | Required | Description                                                                                                                                                                                                                                                 |
| ---------- | ------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `sql`      | string  | Yes      | One SELECT statement; the tenant scope is applied for you. 10 to 4000 characters.                                                                                                                                                                           |
| `max_rows` | integer | No       | Runs ONE read-only SQL SELECT over this property's own lake tables (the tenant scope is applied for you; no comments, UNION or writes) and returns at most `max_rows` rows (1–500, default 100) with the data age per source. From 1 to 500. Default `100`. |

## Errors

A failure answers with its HTTP status and `{ error: { code, message, details? }, request_id }`. Branch on `code` (stable, lower_snake); show `message` to the person. The CLI prints the same `error` with `"ok": false`.

```json
{
  "error": {
    "code": "insufficient_scope",
    "message": "This operation needs the read scope; connect again and allow it.",
    "details": {
      "required_scope": "read"
    }
  },
  "request_id": "req_01JW4KGF3M3Z6BGNC6DCV0VW91"
}
```

| Status | Code                    | When                                                                                                                      |
| ------ | ----------------------- | ------------------------------------------------------------------------------------------------------------------------- |
| 400    | `invalid_request`       | A path, query or body value does not match this page. `details.issues` lists each `location`, `path` and `message`.       |
| 400    | `invalid_request`       | A refused or failing query answers 400 with an instruction to fix the SQL; 429 carries Retry-After.                       |
| 401    | `invalid_token`         | The token is missing, expired or revoked: sign in again (`productmetrics login`). The `WWW-Authenticate` header says why. |
| 402    | `subscription_required` | The workspace has no Pro plan.                                                                                            |
| 403    | `insufficient_scope`    | The token lacks the `read` scope (`details.required_scope`): sign in again and allow it.                                  |
| 404    | `not_found`             | An id in the path does not exist, or the signed-in person cannot open it.                                                 |
| 429    | `rate_limited`          | A refused or failing query answers 400 with an instruction to fix the SQL; 429 carries Retry-After.                       |
| 429    | `rate_limited`          | More than 600 requests a minute for this person: wait the `Retry-After` seconds (60) and retry.                           |

[All Store data and insights operations](/docs/api/store-data)
