# Dashboard Overview

Manage dashboard boards and execute individual blocks to retrieve live data. Boards contain blocks — configurable widgets that display metrics, tables, and charts from store data.

## Board Types and Access

Two board types control visibility:

- **`shared`** — visible to all admin users
- **`private`** — visible only to the owner (`user_id`). When creating a private board via API, `user_id` is auto-set to the authenticated admin user if not provided.

The list endpoint (`GET /V1/dashboard/boards`) automatically filters results — each user sees all shared boards plus their own private boards.

## Date Range

Each board has a `date_range` field that applies to all its blocks by default. Individual blocks can override this via their `config.date_range.is_override` and `config.date_range.range` fields.

The `date_range` field accepts the same values as report time ranges:

`today`, `yesterday`, `last7Days`, `last30Days`, `last90Days`, `last365days`, `week`, `month`, `quarter`, `year`, `prev_week`, `prev_month`, `prev_year`, `lifetime`

## Board CRUD

### Workflow

1. List boards:
```
GET /V1/dashboard/boards?searchCriteria=
```

2. Get a single board with all its blocks:
```
GET /V1/dashboard/board/{boardId}
```

3. Create a board:
```json
{
  "endpoint": "/V1/dashboard/board",
  "method": "POST",
  "body": {
    "board": {
      "title": "My Dashboard",
      "type": "shared",
      "date_range": "last30Days",
      "blocks": []
    }
  }
}
```

4. Update a board (only changed fields needed, but blocks are replaced entirely when provided):
```json
{
  "endpoint": "/V1/dashboard/board/{boardId}",
  "method": "PUT",
  "body": {
    "board": {
      "title": "Updated Title",
      "date_range": "last7Days"
    }
  }
}
```

5. Delete a board:
```
DELETE /V1/dashboard/board/{boardId}
```

## Executing Blocks

Retrieve live data from any block without opening the admin UI.

### Workflow

1. Get the board to find block identifiers:
```
GET /V1/dashboard/board/{boardId}
```
Each block in the response has an `identifier` field (e.g., `90bff1067d8d3b2f`).

2. Execute a block:
```json
{
  "endpoint": "/V1/dashboard/board/{boardId}/block/{blockIdentifier}/execute",
  "method": "POST"
}
```

The response contains the same data structure as reports: `columns`, `items`, `totals`, and `size`.

### Response by Renderer Type

- **`single`** — totals contain the main metric value. The column key matches the block's `config.column` (e.g., `sales_order|grand_total__sum`). Comparison values are in keys prefixed with `C|`.
- **`table`** — items contain rows with columns matching the block's configured `dimensions` and `columns`.
- **`chart`** — items contain data points grouped by the dimension (e.g., day, week, month). Each item has columns for the configured metrics.
- **`html`** — returns a single item with the raw HTML content from `config.html_content`.

### Date Filtering

When executing a block, the date range is determined by:
1. If the block has `config.date_range.is_override = true`, the block's own `config.date_range.range` is used.
2. Otherwise, the board's `date_range` is used.
3. If the board's range is `lifetime`, no date filter is applied.

## Sharing / Remote Access

Boards can be shared externally via a token-based URL — no admin login required.

### Fields

- `is_mobile_enabled` (bool) — enables remote access for the board. When `true`, the board is accessible via its token URL.
- `mobile_token` (string) — auto-generated SHA256 hash on first save. Acts as the access key. Read it from the board to build share URLs.
- `is_mobile_frontend` (bool) — when `true`, the board is also accessible on the storefront (public). When `false`, remote access works only through the admin URL.

### Share URLs

- **Admin remote access:** `https://{domain}/admin/dashboard/dashboard/mobile?token={mobile_token}`
- **Storefront (public) access:** `https://{domain}/dashboard/dashboard/mobile?token={mobile_token}` — requires both `is_mobile_enabled = true` AND `is_mobile_frontend = true`.

### Workflow

1. Enable sharing on a board:
```json
{
  "endpoint": "/V1/dashboard/board/{boardId}",
  "method": "PUT",
  "body": {
    "board": {
      "is_mobile_enabled": true,
      "is_mobile_frontend": true
    }
  }
}
```

2. Read the board to get the `mobile_token`:
```
GET /V1/dashboard/board/{boardId}
```

3. Build the share URL using the token from the response.

4. To reset the token, set `mobile_token` to an empty string and save — a new token is generated on next save.

## Block Configuration

See the separate **Block Config API Reference** document for detailed field definitions, required fields per renderer type, and examples for creating blocks.

## Pitfalls

- Block `identifier` values are auto-generated hashes when created via admin UI. When creating blocks via API, you can set any unique string (e.g., `revenue`, `top-products`).
- Block `pos` (position) is `[column, row]` and `size` is `[width, height]` in grid units. These control layout in the admin UI but don't affect API data retrieval.
- Private boards return 404 when accessed by a different admin user — the error message intentionally doesn't reveal the board exists.
- The execute endpoint returns 404 if the block identifier doesn't match any block in the board.
- Chart blocks return data via the execute endpoint even though they can't be rendered in emails.
- Setting `is_mobile_frontend = true` without `is_mobile_enabled = true` has no effect — both must be true for storefront access.
