Skip to content

Records In and Out

By the end of this chapter you can put records in, find them again with filters that combine, change one and delete one — and you will have met the one real bug this lab found, twice, with the workaround that avoids it.

In the app, briefly

In the grid, a record is a row: click the empty row at the bottom, type, press enter. A form view (chapter 8) gives each record a page of labelled boxes instead, which is the kinder way to hand data entry to someone else. Everything below is the same machinery through the API, because that is where this lab could prove each step.

In, through the API

curl -X POST http://localhost:18104/api/v2/tables/<items-id>/records \
  -H "xc-auth: <token>" \
  -d '[{"Name":"Garage Shelf"}, ...]'

The lab inserted its three locations and eight items this way (transcript t05). Two observations from that run are worth more than the call itself. First, the answer was an empty list and HTTP 200 — this build does not echo what it inserted, so a script must read the table back to know the new rows' Id values. Second, a field for a link inside an insert is silently ignored — the row lands with the link empty, no error anywhere. Links get their own chapter and their own endpoint, for exactly this reason.

Finding them again

Reading is a GET on the same address, and the query string is where the spreadsheet's filter button turns into a language (transcript t06):

?where=(Category,eq,Tools)&sort=-Quantity&fields=Name,Quantity,TotalValue
[{"Name":"Box of screws (assorted)","Quantity":4,"TotalValue":26},
 {"Name":"Tape measure","Quantity":3,"TotalValue":38.25},
 {"Name":"Cordless drill","Quantity":1,"TotalValue":89.99}]
  • where filters: (field,operator,value), with operators such as eq (equal), neq, gt, lt, ge, le, like (pattern, with % as the wildcard — (Name,like,%iron%) found the cast iron skillet), in, and is. Conditions join with ~and, ~or, ~not: (Category,eq,Kitchen)~and(Quantity,gt,1) returned exactly the skillet.
  • sort=Field orders by a field; sort=-Field reverses it.
  • fields=A,B,C returns only those fields — the same choice the grid's Fields button makes.
  • limit and offset page through long answers, and every list answer carries a pageInfo block with the true totalRows, so a script can count without fetching everything.

Changing and deleting

A PATCH with the row's Id and the fields to change updates in place; a DELETE with the Id removes:

curl -X PATCH .../records -d '{"Id":7,"Quantity":2}'
curl -X DELETE .../records -d '{"Id":9}'

The lab changed the tape measure's quantity from 3 to 2 and read the row back to find its formula had quietly recomputed (38.25 became 25.50) — computed fields are never typed into and never go stale. The delete removed a temporary ninth row and the count went 9 back to 8, verified both times rather than trusted.

The bug, stated plainly

Inserting one row as a single JSON object — the natural way to write it — fails in this build, in a specific and misleading way (transcript t07, reproduced twice):

HTTP 422
{"error":"ERR_INVALID_PK_VALUE","message":
 "Primary key value 'undefined' is invalid for column 'Id'"}

The message sounds like a refusal. It is not: the row is inserted, and only the step that builds the response trips over the new row's key. The workaround is to always send an array of rows, even an array of one, which returns 200 cleanly. The deeper lesson is the one this whole guide runs on: after any write, read back. A status code is a claim; the table is the evidence.