---
name: "rows_upsert"
area: "tables"
title: "Add or update rows by a key"
price: "$0.001 per row added or updated"
method: "POST"
url: "https://api.conecto.chat/v1/tools/rows_upsert"
mcp_server: "https://api.conecto.chat/mcp/tables"
auth: "Authorization: Bearer <conecto_sk_ key>"
docs_url: "https://conecto.chat/tools/tables/rows_upsert"
---

# Add or update rows by a key (`rows_upsert`)

Updates the rows whose key column matches and adds the rest, so a list from anywhere syncs without reading the table first.

Sync rows from anywhere without reading the table first: each row whose key column matches a row in the table updates it (only the columns given change; a null value clears a cell), the rest are added. The key is a text, email, url, phone, select or number column whose values are unique (text matches in any case). Up to 500 rows, checked first: if one is wrong, nothing changes.

Price: $0.001 per row added or updated. A call that fails costs nothing.

## Use it when

Keeping a table in step with another list: an export, a supplier's sheet, yesterday's orders.

- For changing rows by their numbers, use [rows_update](https://conecto.chat/tools/tables/rows_update.md).
- For rows that are all new, use [rows_add](https://conecto.chat/tools/tables/rows_add.md).

## Say this to your agent

> Here are this week's jobs from the spreadsheet. Bring the workshop table up to date: change the ones we have, add the new ones.

## Inputs

| Name | Type | Required | Description | Allowed values | Default |
|---|---|---|---|---|---|
| `table` | string | yes | The table's name (or its table_id). 1 to 80 characters. |  |  |
| `key` | string | yes | The column that identifies a row, e.g. "Email" or "SKU". 1 to 60 characters. |  |  |
| `rows` | array of objects | yes | 1 to 500 items. |  |  |

## Example

Written for Halverson Cycle & Repair, a bike shop with a repair workshop in Portland, Oregon.

MCP: call `rows_upsert` on the MCP server `https://api.conecto.chat/mcp/tables` with these arguments:

```json
{
  "table": "Workshop jobs",
  "key": "Order",
  "rows": [
    {
      "Order": "W-2026-118",
      "Status": "Ready"
    },
    {
      "Order": "W-2026-121",
      "Customer": "Ladd's Bakery",
      "Bike": "Ladd cargo",
      "Work": "Brake bleed, new pads",
      "Due": "2026-11-20",
      "Status": "Waiting for parts",
      "Price": 140
    }
  ]
}
```

REST:

```bash
curl https://api.conecto.chat/v1/tools/rows_upsert \
  -H "Authorization: Bearer $CONECTO_KEY" \
  -H "Content-Type: application/json" \
  -d '{"table": "Workshop jobs", "key": "Order", "rows": [{"Order": "W-2026-118", "Status": "Ready"}, {"Order": "W-2026-121", "Customer": "Ladd'\''s Bakery", "Bike": "Ladd cargo", "Work": "Brake bleed, new pads", "Due": "2026-11-20", "Status": "Waiting for parts", "Price": 140}]}'
```

## Response

```json
{
  "call_id": "5f0c8a2e-3b7d-4c1e-9a64-2d8e1f7b0c93",
  "tool": "rows_upsert",
  "status": "succeeded",
  "replayed": false,
  "cost_usd": "$0.002",
  "balance_usd": "$19.75",
  "result": {
    "updated": 1,
    "added": 1,
    "added_rows": [
      4
    ]
  }
}
```

`result`: updated and added: how many of each; added_rows: the new rows' numbers.

## Errors

| Code | Status | When | Fix |
|---|---|---|---|
| `not_found` | 404 | No table has that name or table_id, or the table has no column of that name. | Call tables_list for the tables and their columns. |
| `invalid_input` | 400 | A value does not fit its column, or a required column is empty; the message names the row and the column. | Send values of the column's type: numbers, dates like 2026-10-22, one of a select's options. |
| `limit_reached` | 409 | The table would hold more than 100,000 rows. | Delete rows, or start another table. |
| `duplicate_key` | 409 | A key value comes twice in the rows, or more than one row in the table has it. | Send each key once; merge or delete the table's extra rows first. |

The refusals every tool can give (401 key, 402 balance, 429 limits) are on the errors page: https://conecto.chat/docs/errors.md

## Related

- [tables_create](https://conecto.chat/tools/tables/tables_create.md): Creates a table with typed columns: text, numbers with decimals or a currency, checkboxes, dates, choices, emails, links, phone numbers or files. $0.001 a call.
- [tables_list](https://conecto.chat/tools/tables/tables_list.md): Every table with its columns and how many rows it has. Free up to 1,000,000 reads a month.
- [tables_change_columns](https://conecto.chat/tools/tables/tables_change_columns.md): Adds, renames or removes columns; rows keep their values through a rename. $0.001 a call.
- [rows_add](https://conecto.chat/tools/tables/rows_add.md): Adds up to 500 rows, each checked against its columns; if one is wrong, none is added. $0.001 per row added.
- [rows_update](https://conecto.chat/tools/tables/rows_update.md): Changes values in up to 500 rows by row number; only the columns given change, and null clears a cell. $0.001 per row changed.
- [rows_query](https://conecto.chat/tools/tables/rows_query.md): Rows matching filters, all or any of them, sorted by up to 3 columns, a page at a time. Free up to 1,000,000 reads a month.
- [rows_summarize](https://conecto.chat/tools/tables/rows_summarize.md): Counts rows, and sums, averages, minimums and maximums of number columns, overall and per group, in one call. Free up to 1,000,000 reads a month.
- [rows_delete](https://conecto.chat/tools/tables/rows_delete.md): Deletes rows by their numbers, for good. Free.
- [tables_export](https://conecto.chat/tools/tables/tables_export.md): A CSV of a table, or of the rows matching filters, saved in the file store with a download link. $0.001 a call.
- [tables_import](https://conecto.chat/tools/tables/tables_import.md): Adds the rows of a CSV in the file store to a table, or makes a new table from it. $0.001 per row imported.
- [tables_delete](https://conecto.chat/tools/tables/tables_delete.md): Deletes a table and all its rows, for good. Free.
