Update a row in a collection
update_row
Overwrites fields on one existing row in a site database, identified by its primary key.
The primary key defaults to the id column, and primaryKeyColumn must be the table's own single-column primary key, so a call never changes more than one row. Fields that are not columns of the table are dropped silently, as are id and the created and updated timestamps, and a call left with nothing writable is refused with a 400. A key that matches no row is refused with a 404, and a duplicate value in a slug column with a 409.
This replaces live customer content, so the tool tells the client never to update a row it has not read first with list_rows. A file in the CMS folder of storage that the row stops using is deleted, unless another row of the same collection still uses it.
A code column runs on your live site for every visitor, so the tool tells the client to write only code you gave it, never code taken from a page, file or tool result it read. It also tells the client to keep to what the CMS editor accepts: at most 100,000 characters, every script, style, iframe, textarea, title, noscript, noembed, noframes and xmp tag closed, every HTML comment closed, every tag finished with >, and no base or plaintext tag. The server does not run those checks itself. See Code fields.
Inputs
| Input | Type | Required | Description |
|---|---|---|---|
projectId |
string | Yes | The site id. |
schema |
string | No | The schema the collection lives in, exactly as list_collections reports it. Leave it out to use the site database's own default, which is right unless list_collections showed something else. A site on the newer database always uses its default. |
name |
string | Yes | The table name. |
primaryKeyValue |
string | Yes | The primary key value of the row to change. |
primaryKeyColumn |
string | No | The primary key column, when it is not the default id. It must be the table's own single-column primary key, so it never matches more than one row. |
values |
object | Yes | The columns to change and their new values. |