## Update Dashboard Widget

`client.EvaluationDashboards.Widgets.Update(ctx, widgetID, params) (*EvaluationDashboardWidgetWithResult, error)`

**patch** `/v5/evaluation-dashboards/{dashboard_id}/widgets/{widget_id}`

Update a widget's fields within this dashboard, using copy-on-write for shared widgets.

If the widget belongs only to this dashboard it is updated in place; if it is
referenced by more than one dashboard, a new widget is created with the updates
applied and swapped into this dashboard's `widget_order`, leaving the other
dashboards' copy untouched. The widget must already be in this dashboard's
`widget_order`, otherwise the call is rejected. The result is recomputed
synchronously when the `query` changes or when the widget was cloned; otherwise the
existing cached result is returned. For `table` widgets, conditional-formatting
column references are re-resolved against the (possibly updated) query on each save.
The dashboard must exist and not be archived.

### Parameters

- `widgetID string`

- `params EvaluationDashboardWidgetUpdateParams`

  - `DashboardID param.Field[string]`

    Path param

  - `Config param.Field[map[string, any]]`

    Body param: Chart-specific display configuration

  - `Query param.Field[EvaluationDashboardWidgetUpdateParamsQueryUnion]`

    Body param: Structured query AST for metric computation (SeriesQuery or MetricQuery)

    - `type SeriesQuery struct{…}`

      Query that returns a series of records (used for table/bar/histogram/donut/scatter widgets).

      Used for widget types: table, bar, histogram, donut, scatter.
      Returns: {"type": "series", "data": [...]}

      Example SQL equivalent:
      SELECT category, AVG(score) as avg_score, COUNT(*) as count
      FROM evaluation_items
      WHERE score > 0.5 AND category = 'test'
      GROUP BY category
      ORDER BY avg_score DESC
      LIMIT 100

      - `Select []SelectItem`

        - `Expression SelectItemExpressionUnion`

          Reference to a column from evaluation_items.data

          Example:
          {"type": "COLUMN", "column": "category"}

          - `type SelectItemExpressionColumn struct{…}`

            Reference to a column from evaluation_items.data

            Example:
            {"type": "COLUMN", "column": "category"}

            - `Column string`

              Column name from evaluation_items.data

            - `Source string`

              Column source: 'data' or 'task_result_cache'

            - `Type string`

              - `const SelectItemExpressionColumnTypeColumn SelectItemExpressionColumnType = "COLUMN"`

          - `type SelectItemExpressionAggregation struct{…}`

            Aggregation function to apply

            Examples:
            {"type": "AGGREGATION", "function": "AVG", "column": "score"}
            {"type": "AGGREGATION", "function": "COUNT", "column": "*"}
            {"type": "AGGREGATION", "function": "PERCENTILE", "column": "score", "params": {"percentile": 95}}

            - `Column string`

              Column to aggregate, or '*' for COUNT(*)

            - `Function string`

              Supported aggregation functions

              - `const SelectItemExpressionAggregationFunctionCount SelectItemExpressionAggregationFunction = "COUNT"`

              - `const SelectItemExpressionAggregationFunctionSum SelectItemExpressionAggregationFunction = "SUM"`

              - `const SelectItemExpressionAggregationFunctionAvg SelectItemExpressionAggregationFunction = "AVG"`

              - `const SelectItemExpressionAggregationFunctionMin SelectItemExpressionAggregationFunction = "MIN"`

              - `const SelectItemExpressionAggregationFunctionMax SelectItemExpressionAggregationFunction = "MAX"`

              - `const SelectItemExpressionAggregationFunctionStddev SelectItemExpressionAggregationFunction = "STDDEV"`

              - `const SelectItemExpressionAggregationFunctionVariance SelectItemExpressionAggregationFunction = "VARIANCE"`

              - `const SelectItemExpressionAggregationFunctionPercentile SelectItemExpressionAggregationFunction = "PERCENTILE"`

              - `const SelectItemExpressionAggregationFunctionCountDistinct SelectItemExpressionAggregationFunction = "COUNT_DISTINCT"`

              - `const SelectItemExpressionAggregationFunctionPercentage SelectItemExpressionAggregationFunction = "PERCENTAGE"`

            - `EvaluationIDs []string`

              Optional subset of evaluation IDs for per-aggregation filtering in evaluation group dashboards.

            - `Params map[string, any]`

              Function parameters (e.g., {'percentile': 95} for PERCENTILE, {'percentage_filters': Filter} for PERCENTAGE)

            - `Source string`

              Column source: 'data' or 'task_result_cache'

            - `Type string`

              - `const SelectItemExpressionAggregationTypeAggregation SelectItemExpressionAggregationType = "AGGREGATION"`

        - `Alias string`

          Optional alias for the selected item

      - `EvaluationIDs []string`

        Optional subset of evaluation IDs to compute on. Only applicable for evaluation group dashboards. If omitted, computes on all evaluations in the group.

      - `Filter Filter`

        Filter conditions (WHERE clause)

        - `Conditions []FilterCondition`

          - `Column string`

            Column name to filter on

          - `Operator string`

            Comparison operator

            - `const FilterConditionOperatorEquals FilterConditionOperator = "="`

            - `const FilterConditionOperatorNotEquals FilterConditionOperator = "!="`

            - `const FilterConditionOperatorGreater FilterConditionOperator = ">"`

            - `const FilterConditionOperatorLess FilterConditionOperator = "<"`

            - `const FilterConditionOperatorGreaterOrEquals FilterConditionOperator = ">="`

            - `const FilterConditionOperatorLessOrEquals FilterConditionOperator = "<="`

            - `const FilterConditionOperatorIn FilterConditionOperator = "IN"`

            - `const FilterConditionOperatorNotIn FilterConditionOperator = "NOT IN"`

            - `const FilterConditionOperatorLike FilterConditionOperator = "LIKE"`

            - `const FilterConditionOperatorNotLike FilterConditionOperator = "NOT LIKE"`

            - `const FilterConditionOperatorIsNull FilterConditionOperator = "IS NULL"`

            - `const FilterConditionOperatorIsNotNull FilterConditionOperator = "IS NOT NULL"`

          - `Source string`

            Column source: 'data' or 'task_result_cache'

          - `Value FilterConditionValueUnion`

            Value to compare against. Not required for IS NULL / IS NOT NULL operators.

            - `string`

            - `float64`

            - `bool`

            - `type FilterConditionValueArray []any`

        - `LogicalOperators []string`

          Logical operators connecting conditions. Length must be len(conditions) - 1

          - `const FilterLogicalOperatorAnd FilterLogicalOperator = "AND"`

          - `const FilterLogicalOperatorOr FilterLogicalOperator = "OR"`

      - `GroupBy []string`

        Columns to group by

      - `LatestOnly bool`

        When True, the widget computes against rows from only the most recent active evaluation in the group (by EvaluationORM.created_at). Only applicable for evaluation group dashboards. Composes with evaluation_ids (latest within the subset). Cannot be combined with per-aggregation evaluation_ids; the use case enforces these rules.

      - `Limit int64`

        Max rows to return

      - `OrderBy []SeriesQueryOrderBy`

        Sort order

        - `Column string`

          Column name to sort by

        - `Direction string`

          Sort direction

          - `const SeriesQueryOrderByDirectionAsc SeriesQueryOrderByDirection = "ASC"`

          - `const SeriesQueryOrderByDirectionDesc SeriesQueryOrderByDirection = "DESC"`

        - `Source string`

          Column source: 'data' or 'task_result_cache'

    - `type MetricQuery struct{…}`

      Query that returns a single metric value (used for metric widgets).

      Used for widget type: metric.
      Enforces exactly 1 aggregation in select.
      Returns: {"type": "metric", "data": ...}

      Example SQL equivalent:
      SELECT AVG(score) as average_score
      FROM evaluation_items

      - `Select []SelectItem`

        - `Expression SelectItemExpressionUnion`

          Reference to a column from evaluation_items.data

          Example:
          {"type": "COLUMN", "column": "category"}

        - `Alias string`

          Optional alias for the selected item

      - `EvaluationIDs []string`

        Optional subset of evaluation IDs to compute on. Only applicable for evaluation group dashboards. If omitted, computes on all evaluations in the group.

      - `Filter Filter`

        Filter conditions (WHERE clause)

      - `LatestOnly bool`

        When True, the widget computes against rows from only the most recent active evaluation in the group (by EvaluationORM.created_at). Only applicable for evaluation group dashboards. Composes with evaluation_ids (latest within the subset). Cannot be combined with per-aggregation evaluation_ids; the use case enforces these rules.

  - `Title param.Field[string]`

    Body param: Widget title

### Returns

- `type EvaluationDashboardWidgetWithResult struct{…}`

  Response model for widget creation - includes widget and computed result

  - `ID string`

    Unique identifier of the widget

  - `AccountID string`

    Account that owns this widget

  - `CreatedAt Time`

    When the widget was created

  - `Title string`

    Widget title

  - `Type EvaluationWidgetTypeEnum`

    Widget type

    - `const EvaluationWidgetTypeEnumBar EvaluationWidgetTypeEnum = "bar"`

    - `const EvaluationWidgetTypeEnumHistogram EvaluationWidgetTypeEnum = "histogram"`

    - `const EvaluationWidgetTypeEnumDonut EvaluationWidgetTypeEnum = "donut"`

    - `const EvaluationWidgetTypeEnumScatter EvaluationWidgetTypeEnum = "scatter"`

    - `const EvaluationWidgetTypeEnumMetric EvaluationWidgetTypeEnum = "metric"`

    - `const EvaluationWidgetTypeEnumTable EvaluationWidgetTypeEnum = "table"`

    - `const EvaluationWidgetTypeEnumMarkdown EvaluationWidgetTypeEnum = "markdown"`

    - `const EvaluationWidgetTypeEnumHeading EvaluationWidgetTypeEnum = "heading"`

    - `const EvaluationWidgetTypeEnumTimeseries EvaluationWidgetTypeEnum = "timeseries"`

  - `Config map[string, any]`

    Display configuration

  - `Object EvaluationDashboardWidgetWithResultObject`

    - `const EvaluationDashboardWidgetWithResultObjectEvaluationWidget EvaluationDashboardWidgetWithResultObject = "evaluation_widget"`

  - `Query EvaluationDashboardWidgetWithResultQueryUnion`

    Structured query AST for computation (SeriesQuery or MetricQuery)

    - `type SeriesQuery struct{…}`

      Query that returns a series of records (used for table/bar/histogram/donut/scatter widgets).

      Used for widget types: table, bar, histogram, donut, scatter.
      Returns: {"type": "series", "data": [...]}

      Example SQL equivalent:
      SELECT category, AVG(score) as avg_score, COUNT(*) as count
      FROM evaluation_items
      WHERE score > 0.5 AND category = 'test'
      GROUP BY category
      ORDER BY avg_score DESC
      LIMIT 100

      - `Select []SelectItem`

        - `Expression SelectItemExpressionUnion`

          Reference to a column from evaluation_items.data

          Example:
          {"type": "COLUMN", "column": "category"}

          - `type SelectItemExpressionColumn struct{…}`

            Reference to a column from evaluation_items.data

            Example:
            {"type": "COLUMN", "column": "category"}

            - `Column string`

              Column name from evaluation_items.data

            - `Source string`

              Column source: 'data' or 'task_result_cache'

            - `Type string`

              - `const SelectItemExpressionColumnTypeColumn SelectItemExpressionColumnType = "COLUMN"`

          - `type SelectItemExpressionAggregation struct{…}`

            Aggregation function to apply

            Examples:
            {"type": "AGGREGATION", "function": "AVG", "column": "score"}
            {"type": "AGGREGATION", "function": "COUNT", "column": "*"}
            {"type": "AGGREGATION", "function": "PERCENTILE", "column": "score", "params": {"percentile": 95}}

            - `Column string`

              Column to aggregate, or '*' for COUNT(*)

            - `Function string`

              Supported aggregation functions

              - `const SelectItemExpressionAggregationFunctionCount SelectItemExpressionAggregationFunction = "COUNT"`

              - `const SelectItemExpressionAggregationFunctionSum SelectItemExpressionAggregationFunction = "SUM"`

              - `const SelectItemExpressionAggregationFunctionAvg SelectItemExpressionAggregationFunction = "AVG"`

              - `const SelectItemExpressionAggregationFunctionMin SelectItemExpressionAggregationFunction = "MIN"`

              - `const SelectItemExpressionAggregationFunctionMax SelectItemExpressionAggregationFunction = "MAX"`

              - `const SelectItemExpressionAggregationFunctionStddev SelectItemExpressionAggregationFunction = "STDDEV"`

              - `const SelectItemExpressionAggregationFunctionVariance SelectItemExpressionAggregationFunction = "VARIANCE"`

              - `const SelectItemExpressionAggregationFunctionPercentile SelectItemExpressionAggregationFunction = "PERCENTILE"`

              - `const SelectItemExpressionAggregationFunctionCountDistinct SelectItemExpressionAggregationFunction = "COUNT_DISTINCT"`

              - `const SelectItemExpressionAggregationFunctionPercentage SelectItemExpressionAggregationFunction = "PERCENTAGE"`

            - `EvaluationIDs []string`

              Optional subset of evaluation IDs for per-aggregation filtering in evaluation group dashboards.

            - `Params map[string, any]`

              Function parameters (e.g., {'percentile': 95} for PERCENTILE, {'percentage_filters': Filter} for PERCENTAGE)

            - `Source string`

              Column source: 'data' or 'task_result_cache'

            - `Type string`

              - `const SelectItemExpressionAggregationTypeAggregation SelectItemExpressionAggregationType = "AGGREGATION"`

        - `Alias string`

          Optional alias for the selected item

      - `EvaluationIDs []string`

        Optional subset of evaluation IDs to compute on. Only applicable for evaluation group dashboards. If omitted, computes on all evaluations in the group.

      - `Filter Filter`

        Filter conditions (WHERE clause)

        - `Conditions []FilterCondition`

          - `Column string`

            Column name to filter on

          - `Operator string`

            Comparison operator

            - `const FilterConditionOperatorEquals FilterConditionOperator = "="`

            - `const FilterConditionOperatorNotEquals FilterConditionOperator = "!="`

            - `const FilterConditionOperatorGreater FilterConditionOperator = ">"`

            - `const FilterConditionOperatorLess FilterConditionOperator = "<"`

            - `const FilterConditionOperatorGreaterOrEquals FilterConditionOperator = ">="`

            - `const FilterConditionOperatorLessOrEquals FilterConditionOperator = "<="`

            - `const FilterConditionOperatorIn FilterConditionOperator = "IN"`

            - `const FilterConditionOperatorNotIn FilterConditionOperator = "NOT IN"`

            - `const FilterConditionOperatorLike FilterConditionOperator = "LIKE"`

            - `const FilterConditionOperatorNotLike FilterConditionOperator = "NOT LIKE"`

            - `const FilterConditionOperatorIsNull FilterConditionOperator = "IS NULL"`

            - `const FilterConditionOperatorIsNotNull FilterConditionOperator = "IS NOT NULL"`

          - `Source string`

            Column source: 'data' or 'task_result_cache'

          - `Value FilterConditionValueUnion`

            Value to compare against. Not required for IS NULL / IS NOT NULL operators.

            - `string`

            - `float64`

            - `bool`

            - `type FilterConditionValueArray []any`

        - `LogicalOperators []string`

          Logical operators connecting conditions. Length must be len(conditions) - 1

          - `const FilterLogicalOperatorAnd FilterLogicalOperator = "AND"`

          - `const FilterLogicalOperatorOr FilterLogicalOperator = "OR"`

      - `GroupBy []string`

        Columns to group by

      - `LatestOnly bool`

        When True, the widget computes against rows from only the most recent active evaluation in the group (by EvaluationORM.created_at). Only applicable for evaluation group dashboards. Composes with evaluation_ids (latest within the subset). Cannot be combined with per-aggregation evaluation_ids; the use case enforces these rules.

      - `Limit int64`

        Max rows to return

      - `OrderBy []SeriesQueryOrderBy`

        Sort order

        - `Column string`

          Column name to sort by

        - `Direction string`

          Sort direction

          - `const SeriesQueryOrderByDirectionAsc SeriesQueryOrderByDirection = "ASC"`

          - `const SeriesQueryOrderByDirectionDesc SeriesQueryOrderByDirection = "DESC"`

        - `Source string`

          Column source: 'data' or 'task_result_cache'

    - `type MetricQuery struct{…}`

      Query that returns a single metric value (used for metric widgets).

      Used for widget type: metric.
      Enforces exactly 1 aggregation in select.
      Returns: {"type": "metric", "data": ...}

      Example SQL equivalent:
      SELECT AVG(score) as average_score
      FROM evaluation_items

      - `Select []SelectItem`

        - `Expression SelectItemExpressionUnion`

          Reference to a column from evaluation_items.data

          Example:
          {"type": "COLUMN", "column": "category"}

        - `Alias string`

          Optional alias for the selected item

      - `EvaluationIDs []string`

        Optional subset of evaluation IDs to compute on. Only applicable for evaluation group dashboards. If omitted, computes on all evaluations in the group.

      - `Filter Filter`

        Filter conditions (WHERE clause)

      - `LatestOnly bool`

        When True, the widget computes against rows from only the most recent active evaluation in the group (by EvaluationORM.created_at). Only applicable for evaluation group dashboards. Composes with evaluation_ids (latest within the subset). Cannot be combined with per-aggregation evaluation_ids; the use case enforces these rules.

  - `Result EvaluationDashboardWidgetResultResponse`

    Computed result for this widget

    - `ID string`

      Unique identifier of the widget result

    - `ComputationStatus string`

      Status: pending, completed, or failed

    - `WidgetID string`

      Widget ID this result belongs to

    - `ComputedAt Time`

      When computation completed

    - `ComputedResult map[string, any]`

      Computed result data. Metric: {type: 'metric', data: 42}, Series: {type: 'series', data: [{x: 'A', y: 10}, ...]}

    - `ErrorMessage string`

      Error message if computation failed

### Example

```go
package main

import (
  "context"
  "fmt"

  "github.com/scaleapi/sgp-dev-go"
  "github.com/scaleapi/sgp-dev-go/option"
)

func main() {
  client := sgpdev.NewClient(
    option.WithAPIKey("My API Key"),
    option.WithAccountID("My Account ID"),
  )
  evaluationDashboardWidgetWithResult, err := client.EvaluationDashboards.Widgets.Update(
    context.TODO(),
    "widget_id",
    sgpdev.EvaluationDashboardWidgetUpdateParams{
      DashboardID: "dashboard_id",
    },
  )
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", evaluationDashboardWidgetWithResult.ID)
}
```

#### Response

```json
{
  "id": "id",
  "account_id": "account_id",
  "created_at": "2019-12-27T18:11:19.117Z",
  "title": "title",
  "type": "bar",
  "config": {
    "foo": "bar"
  },
  "object": "evaluation_widget",
  "query": {
    "select": [
      {
        "expression": {
          "column": "column",
          "source": "source",
          "type": "COLUMN"
        },
        "alias": "alias"
      }
    ],
    "evaluation_ids": [
      "string"
    ],
    "filter": {
      "conditions": [
        {
          "column": "column",
          "operator": "=",
          "source": "source",
          "value": "string"
        }
      ],
      "logicalOperators": [
        "AND"
      ]
    },
    "groupBy": [
      "string"
    ],
    "latest_only": true,
    "limit": 1,
    "orderBy": [
      {
        "column": "column",
        "direction": "ASC",
        "source": "source"
      }
    ]
  },
  "result": {
    "id": "id",
    "computation_status": "computation_status",
    "widget_id": "widget_id",
    "computed_at": "2019-12-27T18:11:19.117Z",
    "computed_result": {
      "foo": "bar"
    },
    "error_message": "error_message"
  }
}
```
