Skip to content

Read and write records over the API, step by step

Create, read, change and list any table's records over plain HTTP, join related tables and count by group in one request, with the same checks, audit trail and access as the app.

7 steps·5 min read·Developers

Every table over plain HTTP, with lookups named for you, joins and summaries in one request, and the caller's own access on every row.

What it is

  • One address per table: /api/v1/data/{table} to create (POST) and list (GET), /api/v1/data/{table}/{id} to read (GET), change (PATCH) and delete (DELETE) one record.
  • Every lookup comes back as three keys: the id, {field}__name and {field}__record_number, so a client never needs a second call to show what a record points to.
  • List reads take $filter (also through a lookup), $select, $orderby, $top (up to 5,000 a page), page, a saved view, links to join related tables, and aggregates with groupby for counts and totals.
  • Writes go through the same pipeline as the app: required fields, defaults, rules and audit. Prefer: return=representation returns the saved record.
  • Every read runs as the caller: rows the caller may not reach are simply not there.

Good to know

  • With no view named, a list reads through the table's default view, usually the active records only.
  • Updates are last writer wins today: a row version you send is accepted but not checked. The record's audit history keeps every change.
  • Count pages with total_count: the has_more flag also answered true on the last page when we tried it.

Before you start

  • Records are read and written at /api/v1/data/{table}, where the table is its schema name: matter, contact, or a table your office added. The same rules apply as in the app: the same checks and defaults, the same audit trail, and the same access, because every call runs as the person or machine that sends it.
  • The example is a law office's Court Appearance table (a custom table: name, court, department, judge, date and time, and the Matter it belongs to). We add a status conference on the Harbor Glen cargo claim, read it, change it, then list and summarize hearings across matters and clients. Every request and answer is a real exchange; record ids and support ids are hidden.

1Create a record: POST /api/v1/data/{table}

Send the fields as JSON, by their schema names. A lookup is set with the id of the record it points to: here matter_id is the Harbor Glen cargo claim. A date and time is sent in UTC with its Z.

Codossier Office answers 201 Created with the new record's id and its address in Location. Fields you leave out take their defaults, and a required field left out is refused with its label ('Date and Time' is required). Add the header Prefer: return=representation to receive the whole record instead of the id.

Read and write records over the API, step 1: Create a record: POST /api/v1/data/{table} (A lookup: the id it points to; Created; Where it lives)
1A lookup: the id it points to2Created3Where it lives

2Read one record: the lookup in three keys

GET /api/v1/data/court_appearance/{id}, with $select for the fields you want (id always comes, and state_id and status_id ride along).

Every lookup comes back as three keys: matter_id (the id), matter_id__name (the name a person sees) and matter_id__record_number. You never need a second call to show what a lookup points to. __access_tier__ says what you hold on this record (here Owner), and __row_version__ is the record's version. Companions of lookups you did not ask for come back empty; the picture leaves them out.

Read and write records over the API, step 2: Read one record: the lookup in three keys (The id; Its name; Its number)
1The id2Its name3Its number

3Change it: PATCH sends only what changes

PATCH /api/v1/data/court_appearance/{id} with only the fields to change: here the courtroom and the judge. Fields you do not send are left as they are; a field sent as null is cleared.

By default the answer is 204 and no body. With Prefer: return=representation, as here, it is the record as saved, with its new modified_on and __row_version__.

The last writer wins today: Codossier Office accepts a __row_version__ or If-Match you send, but does not refuse an update made on an older version. Every change is in the record's audit history, with who made it.
Read and write records over the API, step 3: Change it: PATCH sends only what changes (The record; Send it back to me; Saved)
1The record2Send it back to me3Saved

4List records: filter, through a lookup, sort and page

GET /api/v1/data/court_appearance takes:

  • $filter: eq, ne, gt, ge, lt, le, contains, startswith, endswith, and, or, not. Through a lookup, one level: contains(matter_id/name,'Lease') keeps the hearings of matters whose name contains Lease. The __name keys cannot be filtered: go through the lookup instead.
  • $select, $orderby (one column and its direction: write asc or desc), $top (rows per page, up to 5,000) and page.
  • view to read through a saved view. With no view, the table's default view applies, with its filter (usually the active records only).

The answer gives items, total_count (every row the filter matches), the page and page_size. Companions of lookups you did not ask for come back empty; the picture leaves them out.

To walk every page, count with total_count and page_size: has_more also answered true on the last page here.
Read and write records over the API, step 4: List records: filter, through a lookup, sort and page (Filter through the lookup; All that match; This page)
1Filter through the lookup2All that match3This page

5Join related tables in one read: links

To bring columns from related tables, add links: a small JSON tree of joins, each following a real lookup. Here each hearing joins its matter (m, through matter_id), and each matter its client account (c, through account_id). Name the joined columns in $select as alias.column: m.name, c.name, c.address_city.

One request answers one row per hearing with the matter and the client beside it. A condition on a joined column filters through the join, and every joined table is read with your access. Companions of lookups you did not ask for come back empty; the picture leaves them out.

Read and write records over the API, step 5: Join related tables in one read: links (The joins and their aliases; From the matter; From the client)
1The joins and their aliases2From the matter3From the client

6Summarize: counts and totals by group

Instead of rows, ask for a summary: aggregates (a JSON list: an alias, a function among count, count_distinct, sum, avg, min, max, and a column) and groupby. Here, per matter, how many hearings and the earliest one.

The answer is one row per group. A lookup you group by comes back with its name and number, so the result is ready to show.

Read and write records over the API, step 6: Summarize: counts and totals by group (What to count, by what; One row per matter; Named for you)
1What to count, by what2One row per matter3Named for you

7Access is applied on every read

The same table, read with the API key of a service account that holds no role yet. The call is accepted (the key is valid), but the account reaches no hearing, so the list is simply empty: total_count 0. There is no way around it: the API never reads as anyone but the caller.

Give the account a role that reaches the table and the same call returns the rows that role allows. Each person and machine sees what its roles, its team memberships and the records it is linked to allow.

Read and write records over the API, step 7: Access is applied on every read (A machine's key (hidden); Nothing it may see)
1A machine's key (hidden)2Nothing it may see

What next