# Update Analytics Data Source Table

Change some of a fixed source's table without sending the rest, then save it, as Save in the app's Edit table does: the panels and merges that read it follow. Read it first with Get Analytics Data Source Table and send its revision in If-Match; if the table changed since, nothing is saved (412). Operations apply in order, all or none: setCells changes values, insertRows adds rows (each keyed by column, as the table reads them), deleteRows removes them. Values are text, or null for empty, and must fit their column's type. The answer is the table's first rows after the update, with the new revision in meta.revision and the ETag header, and what changed in meta.changes. To replace every row, use Update Analytics Data Source with rows.

`PUT https://connect.mindcloud.co/v2/analytics/data-sources/:dataSourceId/table`

Permissions: `analytics:page:create`.

## Parameters

### Path

- `dataSourceId` (string, required): The fixed source's id, from List Analytics Data Sources.

### Headers

- `If-Match` (string, required): Required. The revision you last read: the `revision` from its read (Get Workflow Definition for a workflow, Get Analytics Page Definition for an Analytics page, Get Analytics Data Source Table for a fixed source's table), or `meta.revision` from your last change to it. The `ETag` header of either answer is the same value, ready to send back. The change applies only if nobody changed it since: otherwise it answers 412 with the current revision in `error.details.revision`. Send it as a strong entity tag (`"r_..."`): a weak one (`W/"..."`) never matches and answers 412. Without it the request answers 428.
- `X-Company-Id` (string): Optional. The id of the organization to act in. Leave it out to act in the API key's own organization. Here a key acts in another organization only as one of its members: with "Use this key across all of your organizations" on, in an organization its creator belongs to with a role. Child organizations and MindCloud staff access do not reach this endpoint. Every response's X-Company-Id header names the organization it acted in. See [Organizations](https://mindcloud.co/docs/api/rest/introduction/organizations).

### Body

- `operations` (array): The changes, in order.
  The changes, applied in order: setCells, insertRows and deleteRows. Row indexes count from 0 in the table as it stands after the operations before it. All of them apply, or none.
  Default: `[]`
- `addColumns` (array): Columns to add, each with a name and a type.
  Columns to add after the existing ones, empty until operations fill them.
  Default: `[]`
  - `name` (string, required): The new column's key.
  - `type` (string, required): What the column holds: text, wholeNumber, decimal, yesNo, date or dateTime.
    Allowed values:
      - `text`: Text.
      - `wholeNumber`: A whole number.
      - `decimal`: A decimal number.
      - `yesNo`: Yes or no.
      - `date`: A date.
      - `dateTime`: A date and time.
- `confirmationReceipt` (string): The receipt a 409 ANALYTICS_EMBED_CONFIRMATION_REQUIRED answered, to confirm the change to published embeds.
  Only after a 409 ANALYTICS_EMBED_CONFIRMATION_REQUIRED for the same request: the confirmationReceipt from its error.details, confirming the change to the published embeds it lists.

## Example request

```bash
curl --request PUT \
  --url 'https://connect.mindcloud.co/v2/analytics/data-sources/Ds3Hq9Lp2WxM/table' \
  --header 'Authorization: Bearer $MINDCLOUD_API_TOKEN' \
  --header 'Content-Type: application/json' \
  --data '{
  "operations": [
    {
      "type": "setCells",
      "cells": [
        {
          "rowIndex": 3,
          "columnKey": "target",
          "value": "125000"
        }
      ]
    }
  ],
  "addColumns": [
    {
      "name": "region",
      "type": "text"
    }
  ],
  "confirmationReceipt": "eyJmaW5nZXJwcmludCI6IjhkNGMifQ"
}'
```

## Response fields

- `id` (string): The data source's id.
- `revision` (string): The table as read, also in the ETag header. Send it in If-Match to Update Analytics Data Source Table; an update to a table changed since is refused.
- `columnTypes` (array of objects): Every column, in order, with its stored type.
  - `key` (string): The column's key.
  - `type` (string): The column's stored type, such as VARCHAR, BIGINT or DATE.
- `columns` (array of string): The column names the rows carry, in order.
- `rows` (array of objects): The rows in this window, as objects keyed by column.
- `rowCount` (number): How many rows there are in all.
- `offset` (number): Where this window starts.
- `nextOffset` (number): The offset of the next window, or null when this is the last.
