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

> ## Agent Instructions
> Automate.ax automations are TypeScript programs.
> Use Bun for installation and command examples.
> Use Automate.ax for the product name and automate.ax for the package, CLI, and domain.
> Treat documented public APIs as current; do not invent transitional or deprecated names.

# Upsert rows

> Update uniquely keyed Google Sheets rows and append records with new keys.

`upsertRows` matches each input record by one or more exact header columns,
patches existing matches, and appends new keys.

## Example

```ts theme={null}
import { automation, onHttpRequest } from "automate.ax"
import { upsertRows } from "automate.ax/google-sheets"

export default automation("Synchronize orders", () => {
  onHttpRequest({ scope: "automation" })

  upsertRows({
    spreadsheet: "spreadsheet-id",
    source: { table: "OrdersTable" },
    keyColumns: ["Order ID"],
    rows: [
      { "Order ID": "A-1042", Status: "Closed" },
      { "Order ID": "A-1043", Status: "Open", Total: 80 },
    ],
  })
})
```

## Inputs

`spreadsheet`, `source`, non-empty exact `keyColumns`, and one or more records
are required. Every input record must have a non-null value for every key;
partial non-key fields patch existing rows, while omitted fields become null on
new rows. `inputMode` defaults to `userEntered`.

`account` optionally selects the Google account binding.

## Output

Returns `{ affectedCells, insertedRows, insertedRange?, updatedRowNumbers }`.
`insertedRange` is available for ordinary sheets, not native tables. The action
fails when existing rows share a composite key or input records contain
duplicate keys, preventing ambiguous updates.
