# POST /api/v1/dashboards/{dashboard_id}/widgets

> Add a widget

- **Tag:** dashboards
- **Operation ID:** `add_widget_api_v1_dashboards__dashboard_id__widgets_post`

## Description

Add a widget from a chat card ('Add to dashboard') or manually. The snapshot payload is stored verbatim; a source tool, when provided, must be a READ tool.

## Authentication

Bearer token in `Authorization` header.
Required header: `x-business-id: <business uuid>`.

## Parameters

- `dashboard_id` (path, string, required)

## Request body

Schema: `AddWidgetRequest`

- `title` (string · required)
- `widget_type` (string · required) (one of: chart, table, metric, text)
- `layout` (WidgetLayout)
- `source` (WidgetSource)
- `snapshot` (WidgetSnapshot)
- `body` (string)

## Responses

### 201 — Successful Response

Schema: `SuccessEnvelope_DashboardResponse_`

- `success` (boolean)
- `message` (string)
- `code` (string)
- `data` (DashboardResponse)

### 400 — Bad Request - Invalid input

### 401 — Unauthorized - Authentication required

### 403 — Forbidden - Insufficient permissions

### 404 — Not Found - Resource does not exist

### 422 — Validation Error

Schema: `HTTPValidationError`

- `detail` (array · ValidationError) → `ValidationError`
  - `loc` (array · string | integer · required)
  - `msg` (string · required)
  - `type` (string · required)
  - `input` (object)
  - `ctx` (object)

## Code samples

### cURL

```bash
curl -X POST 'https://api.ondayzero.com/api/v1/dashboards/{dashboard_id}/widgets' \
  -H 'Authorization: Bearer dz_your_token' \
  -H 'x-business-id: YOUR_BUSINESS_ID' \
  -H 'Content-Type: application/json' \
  -d '{
  "title": "string",
  "widget_type": "chart"
}'
```

### JavaScript

```javascript
const response = await fetch('https://api.ondayzero.com/api/v1/dashboards/{dashboard_id}/widgets', {
  method: 'POST',
  headers: {
    Authorization: 'Bearer dz_your_token',
    'x-business-id': 'YOUR_BUSINESS_ID',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
  "title": "string",
  "widget_type": "chart"
}),
});
const data = await response.json();
```

### Python

```python
import httpx

headers = {
    "Authorization": "Bearer dz_your_token",
    "x-business-id": "YOUR_BUSINESS_ID",
}

payload = {
  "title": "string",
  "widget_type": "chart"
}

response = httpx.post("https://api.ondayzero.com/api/v1/dashboards/{dashboard_id}/widgets", headers=headers, json=payload)
data = response.json()
```

## See also

- HTML version: https://www.ondayzero.com/docs/reference/dashboards/add-widget
- OpenAPI slice: https://www.ondayzero.com/docs/reference/dashboards/add-widget/openapi.json
- Other endpoints in **dashboards**: https://www.ondayzero.com/docs/reference/dashboards
