> ## Documentation Index
> Fetch the complete documentation index at: https://code.dcycle.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Update Dashboard

> Update a dashboard's widgets and layouts

# Update Dashboard

Update a dashboard's widgets and/or layouts. Only the organization that owns the project can modify its dashboards — child organizations in the hierarchy have read-only access.

<Note>
  Unknown fields are rejected (`extra = "forbid"`). Only send `widgets` and/or `layouts` in the request body.
</Note>

## Request

### Headers

<ParamField header="x-api-key" type="string" required>
  Your API key for authentication

  **Example:** `sk_live_1234567890abcdef`
</ParamField>

<ParamField header="x-organization-id" type="string" required>
  Your organization UUID

  **Example:** `a8315ef3-dd50-43f8-b7ce-d839e68d51fa`
</ParamField>

### Path Parameters

<ParamField path="dashboard_id" type="string" required>
  UUID of the dashboard to update

  **Example:** `"550e8400-e29b-41d4-a716-446655440000"`
</ParamField>

### Body Parameters

<ParamField body="widgets" type="array">
  Updated list of widget configurations. Each widget requires `id`, `name`, and `config`.
</ParamField>

<ParamField body="layouts" type="object">
  Updated responsive grid layouts by breakpoint (`lg`, `md`, `sm`, `xs`, `xxs`).
</ParamField>

## Response

Returns the updated dashboard object with HTTP 200.

<ResponseField name="id" type="string">
  Dashboard UUID
</ResponseField>

<ResponseField name="project_id" type="string">
  UUID of the associated project
</ResponseField>

<ResponseField name="widgets" type="array">
  Updated list of widget configurations
</ResponseField>

<ResponseField name="layouts" type="object">
  Updated responsive grid layouts
</ResponseField>

<ResponseField name="created_at" type="datetime">
  Creation timestamp (ISO 8601)
</ResponseField>

<ResponseField name="updated_at" type="datetime | null">
  Last update timestamp (ISO 8601)
</ResponseField>

## Example

<CodeGroup>
  ```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  curl -X PATCH "https://api.dcycle.io/v2/dashboard/550e8400-e29b-41d4-a716-446655440000" \
    -H "x-api-key: ${DCYCLE_API_KEY}" \
    -H "x-organization-id: ${DCYCLE_ORG_ID}" \
    -H "Content-Type: application/json" \
    -d '{
      "widgets": [
        {
          "id": "widget-1",
          "name": "Total Emissions 2024",
          "type": "bar_chart",
          "config": {
            "metrics": [{
              "id": "m1",
              "category": "emissions",
              "filters": [],
              "aggregation": { "organizations": [{ "id": "org-uuid" }] }
            }],
            "periodicity": "monthly",
            "periods": [{ "start_date": "2024-01-01", "end_date": "2024-12-31" }],
            "unit": "tCO2e"
          }
        }
      ],
      "layouts": {
        "lg": [{ "i": "widget-1", "x": 0, "y": 0, "w": 12, "h": 6 }],
        "md": [{ "i": "widget-1", "x": 0, "y": 0, "w": 10, "h": 6 }],
        "sm": [{ "i": "widget-1", "x": 0, "y": 0, "w": 6, "h": 4 }],
        "xs": [{ "i": "widget-1", "x": 0, "y": 0, "w": 4, "h": 4 }],
        "xxs": [{ "i": "widget-1", "x": 0, "y": 0, "w": 2, "h": 4 }]
      }
    }'
  ```

  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import requests
  import os

  headers = {
      "x-api-key": os.getenv("DCYCLE_API_KEY"),
      "x-organization-id": os.getenv("DCYCLE_ORG_ID"),
      "Content-Type": "application/json",
  }

  dashboard_id = "550e8400-e29b-41d4-a716-446655440000"

  response = requests.patch(
      f"https://api.dcycle.io/v2/dashboard/{dashboard_id}",
      headers=headers,
      json={
          "widgets": [
              {
                  "id": "widget-1",
                  "name": "Total Emissions 2024",
                  "type": "bar_chart",
                  "config": {
                      "metrics": [{"id": "m1", "category": "emissions"}],
                      "periodicity": "monthly",
                      "periods": [{"start_date": "2024-01-01", "end_date": "2024-12-31"}],
                      "unit": "tCO2e",
                  },
              }
          ],
          "layouts": {
              "lg": [{"i": "widget-1", "x": 0, "y": 0, "w": 12, "h": 6}],
          },
      },
  )

  dashboard = response.json()
  print(f"Updated: {len(dashboard['widgets'])} widgets")
  ```

  ```javascript JavaScript theme={"theme":{"light":"github-light","dark":"github-dark"}}
  const axios = require('axios');

  const headers = {
    'x-api-key': process.env.DCYCLE_API_KEY,
    'x-organization-id': process.env.DCYCLE_ORG_ID,
    'Content-Type': 'application/json',
  };

  const dashboardId = '550e8400-e29b-41d4-a716-446655440000';

  axios.patch(`https://api.dcycle.io/v2/dashboard/${dashboardId}`, {
    widgets: [{
      id: 'widget-1',
      name: 'Total Emissions 2024',
      type: 'bar_chart',
      config: {
        metrics: [{ id: 'm1', category: 'emissions' }],
        periodicity: 'monthly',
        periods: [{ start_date: '2024-01-01', end_date: '2024-12-31' }],
        unit: 'tCO2e',
      },
    }],
  }, { headers })
  .then(response => console.log(`Updated: ${response.data.widgets.length} widgets`));
  ```
</CodeGroup>

### Successful Response

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "project_id": "a8315ef3-dd50-43f8-b7ce-d839e68d51fa",
  "widgets": [
    {
      "id": "widget-1",
      "name": "Total Emissions 2024",
      "type": "bar_chart",
      "config": { ... }
    }
  ],
  "layouts": {
    "lg": [{ "i": "widget-1", "x": 0, "y": 0, "w": 12, "h": 6 }],
    "md": [],
    "sm": [],
    "xs": [],
    "xxs": []
  },
  "created_at": "2024-11-24T10:30:00Z",
  "updated_at": "2024-12-20T09:15:00Z"
}
```

## Common Errors

### 401 Unauthorized

**Cause:** Missing or invalid API key

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{"detail": "Invalid API key for organization", "code": "INVALID_API_KEY"}
```

### 403 Forbidden

**Cause:** The user is not a member of the organization, or your organization is not the owner of this dashboard's project

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{"detail": "Logged User is not Member of Organization", "code": "LOGGED_USER_NOT_MEMBER"}
```

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "detail": "Only the owning organization can modify this dashboard."
}
```

### 404 Not Found

**Cause:** Dashboard does not exist

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "detail": "Not found."
}
```

### 422 Validation Error

**Cause:** Request body contains unknown fields

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "detail": [
    {
      "loc": ["body", "unknown_field"],
      "msg": "extra fields not permitted",
      "type": "value_error.extra"
    }
  ]
}
```

## Related Endpoints

<CardGroup cols={2}>
  <Card title="Get Dashboard" icon="chart-mixed" href="/api-reference/dashboards/get">
    View the current dashboard state
  </Card>

  <Card title="Delete Dashboard" icon="trash" href="/api-reference/dashboards/delete">
    Remove a dashboard
  </Card>
</CardGroup>
