Syncing a lookup table
A lookup table is often a copy of data that lives in another system: the vendor master in your ERP, open purchase orders, cost centres. Two calls keep it in step with that system without replacing every record each time. Both match a row to a record by a key column, your system's own identifier for the record (a vendor code, a PO number), so records keep their ids and only what changed is written.
Both need the Edit lookup table records permission (catalog.record.write) for the table, as adding or editing a record does.
The key column
The key column is a column of the table that:
- holds text or numbers (not a list),
- is marked Unique when present in the table's columns,
- is not the system's Internal ID.
Text keys are compared without case, spaces, punctuation or accents, so V-001 and v 001 are the same key; number keys by value, so 10 and 10.0 are the same key. Another column is refused with 400 and lookup_key_column_invalid.
Sending changes: the record batch
Send what changed since your last sync: new and changed records as upsert, removed ones as delete. Up to 5,000 operations in one call, saved as one version of the table.
curl -X POST "https://app.docaifabric.com/api/tenants/{tenant_id}/lookup-tables/{table_id}/records/batch" \
-H "X-API-Key: your-api-key" \
-H "Content-Type: application/json" \
-d '{
"key_column": "vendor_code",
"operations": [
{"op": "upsert", "data": {"vendor_code": "V-001", "name": "Acme GmbH", "iban": "DE89370400440532013000"}},
{"op": "upsert", "data": {"vendor_code": "V-002", "name": "Bolt Ltd", "iban": "GB29NWBK60161331926819"}},
{"op": "delete", "key": "V-017"}
]
}'
upsert:dataholds the record's values by column id, the key column's included. A new key adds a record. A key the table holds updates that record with the columns you send; columns you leave out keep their values. A record that already holds those values is left as it is.delete:keynames the record by its key;idnames it by its id, and needs nokey_column.
The answer lists one result per operation, in order:
{
"results": [
{"index": 0, "op": "upsert", "outcome": "updated", "id": "4f0c…"},
{"index": 1, "op": "upsert", "outcome": "conflict", "id": null,
"column_id": "iban", "conflicting_id": "9a1e…"},
{"index": 2, "op": "delete", "outcome": "deleted", "id": "77b2…"}
],
"counts": {"updated": 1, "conflict": 1, "deleted": 1},
"version": 42,
"saved": true
}
| Outcome | Meaning |
|---|---|
added | A new record, for a key the table did not hold. |
updated | The record with this key took the values sent. |
unchanged | The record already held them; nothing was written. |
deleted | The record is gone. |
not_found | No record has this key or id. |
skipped_no_key | The upsert's key column is empty; nothing was written. |
conflict | Not written: another record already holds a value of this row in a column marked unique (column_id and conflicting_id name it), or several records hold the key. A row is never merged into another record. |
saved is false when nothing changed: the table keeps its version.
A failed batch. A value the table refuses (text in a number column, a required column left empty) stops the batch with 400 and record_batch_failed. The operations before it are saved; results lists them, and failed_index is the one that failed. Fix it and send the same batch again: an upsert or a delete by key gives the same table however often it is repeated.
Sending the whole table: the sync import
When your system exports the whole table at once, import the file in mode sync. The file is the table: rows with a new key are added, changed rows update their record, and records whose key is not in the file are deleted. Records with no value in the key column (added by hand, say) are kept.
curl -X POST "https://app.docaifabric.com/api/tenants/{tenant_id}/lookup-tables/{table_id}/import" \
-H "X-API-Key: your-api-key" \
-F "file=@vendors.csv" \
-F 'config={"mode": "sync", "key_column": "vendor_code", "column_mapping": {"Vendor code": "vendor_code", "Name": "name", "IBAN": "iban"}}'
The answer counts what happened: records_created, records_updated, records_unchanged, records_deleted, records_without_key, and in errors the rows that were not written (an empty key, a value another record holds in a unique column, a value the table refuses), each by its row number. Those rows' records stay as they are.
The table the file describes is worked out whole before anything is written, so the order of the rows does not matter: a vendor renumbered in your system keeps its IBAN (the old record goes, the new one takes it), and a value one row moves to another is applied either way. Two rows that claim the same value in a unique column are both left out.
The whole import is refused, and nothing is written, when:
- a row of the file cannot be read, since its record would otherwise be deleted as missing;
- two rows have the same key;
- no row has a value in the key column (the key column left out of
column_mapping, a file with another delimiter or a renamed header, an empty file), since the sync would otherwise delete every record.
The file's own Internal ID column, if it has one, is ignored.
A ZIP the table's export wrote (schema.json and data.csv) syncs back the same way, with no column_mapping.
Which one to use
| You have | Use |
|---|---|
| The changes since the last sync (new, changed, removed) | The record batch |
| The whole table, as your system exports it | The sync import |
| A file that only adds rows, or replaces the table and its record ids | The import in mode append or replace |
Translating a lookup table for reviewers
A lookup table in the documents' language (a Chinese vendor master for Chinese invoices) can be translated for reviewers who do not read it. The translations are for people reading and searching the table: the Table Lookup rule never reads them, a record's data and the table's export never hold them, and picking a record writes its original values.
Give the table up to five languages, codes of the Translate step's list, and switch Translate on for the columns to translate: a text column, a text list column, or a text sub-column of an object list. Both are changes to the table's settings and need the Manage lookup tables permission (catalog.manage).
curl -X PUT "https://app.docaifabric.com/api/tenants/{tenant_id}/lookup-tables/{table_id}" \
-H "X-API-Key: your-api-key" \
-H "Content-Type: application/json" \
-d '{"translation_languages": ["en"]}'
A column's Translate switch is its translate flag, true or false, sent with the rest of the table's schema in the same call, as any change to a column is.
The tenant's translate model then translates every distinct text of those columns in the background, which spends model usage and counts against the tenant's budget. After that, only texts it has not seen are translated: a new record's, a changed value's. Up to 100,000 distinct texts per language are translated.
GET /api/tenants/{tenant_id}/lookup-tables/{table_id}/translations answers each language's state (up_to_date, running, waiting, budget_reached, no_model, too_many_texts) and counts, and how many distinct texts each column holds: what switching it on would translate. Counting the columns reads every record; ?columns=false answers the languages alone, with an empty column list, for a client that checks the progress often. POST /api/tenants/{tenant_id}/lookup-tables/{table_id}/translations/{language}/translate-again translates every text again, after a change of model for example; the old translations stay in use until the new ones are complete.
Reading and searching with translation_language:
POST /api/tenants/{tenant_id}/lookup-tables/{table_id}/searchwith"translation_language": "en"also finds a record by the translation of a column with Translate on, after the records found by their originals. Each record carriestranslated_data, the shape ofdataholding each value's translation (nullwhere a value has none), andmatched_by, the columns whose translation matched; the page carries the language'stranslation_state.GET /api/tenants/{tenant_id}/lookup-tables/{table_id}/recordsandGET /api/tenants/{tenant_id}/lookup-tables/{table_id}/records/{record_id}, with?translation_language=en, carrytranslated_datatoo.- A language not on the table's list answers no translations, never an error.
Without translation_language every answer is as before.