Receiving documents with an intake
An intake turns documents another system sends into records. You define once how a document’s values map onto your tables. After that, every document delivered to the intake becomes those records in one write: an invoice and its lines, an order and its items. Each value keeps a note of where it came from.
An intake translates; it grants nothing. A delivery runs as its caller, so every record, file and evidence row it writes needs the caller’s own permission.
The definition
Section titled “The definition”A definition names the kind of document it accepts, the record it makes, and where each value goes:
{ "documentKind": "textract-expense", "files": { "document": "textract_json", "source": "scan" }, "root": { "table": "invoices", "fields": [ { "from": { "summary": "INVOICE_RECEIPT_ID" }, "to": "invoice_number" }, { "from": { "summary": "INVOICE_RECEIPT_DATE" }, "to": "invoice_date", "rules": [{ "rule": "dateFormat", "pattern": "DD/MM/YYYY" }] }, { "from": { "summary": "TOTAL", "pick": "highestConfidence" }, "to": "total" }, { "from": { "summary": "VENDOR_NAME" }, "to": "supplier", "rules": [{ "rule": "resolveReference", "table": "suppliers", "keyField": "name", "mode": "normalised" }] } ], "evidence": { "metadataTable": "detections", "fields": { "page": "page", "box": "value.box", "read_text": "value.text", "value_confidence": "value.confidence" } }, "children": [ { "each": { "lineItems": true }, "table": "invoice_lines", "link": "invoice", "fields": [ { "from": { "lineField": "ITEM" }, "to": "description" }, { "from": { "lineField": "PRICE" }, "to": "amount" } ] } ] }, "corrections": []}| Part | Says |
|---|---|
documentKind |
textract-expense for AWS Textract AnalyzeExpense output, or json for any JSON document checked against a documentSchema you give. |
files |
Two attachment fields on the root table: one keeps the document, one keeps the source file, such as the scanned PDF. |
root |
The record each document makes: its table and where each value goes. |
fields |
Each value: a selector (from), a field (to), and optional import rules that convert it first. |
evidence |
A metadata table on the record’s table, and which part of each value goes into which of its fields. |
children |
Records made from each entry a selector finds, such as each line item, linked to their parent through the reference field link. Records nest at most three levels deep. |
corrections |
Correction rules that set values on the records before they are written. |
Selectors
Section titled “Selectors”| Kind | Selector | Finds |
|---|---|---|
textract-expense |
{ "summary": "TOTAL" } |
A summary field by its Textract type. pick chooses among several: highestConfidence (the default), first or last. OTHER fields take a label, the text printed beside the value. |
textract-expense |
{ "lineField": "PRICE" } |
A field of one line item, inside a { "lineItems": true } child. |
json |
{ "pointer": "/header/total" } |
The value at a JSON pointer, relative to the record’s place in the document. A child iterates with { "each": "/lines/*" }. |
A selector that finds nothing leaves the field empty. A pointer that reaches an object or an array finds nothing: a field takes a value, never a structure.
Evidence
Section titled “Evidence”Each value can record where it came from. For textract-expense the parts are
page, type.text, type.confidence, label.text, label.confidence,
value.text, value.confidence and value.box, a region on the page. For
json the one part is value.text. The metadata table needs a field of a
matching type for each part it keeps (a region for value.box, a number for a
confidence, an integer for page), and it must cover every field the intake
maps.
Correction rules
Section titled “Correction rules”A correction rule sets values the document gets wrong or leaves out, on every delivery, before anything is written:
{ "name": "northwind-facilities", "table": "invoice_lines", "when": [ { "of": "root", "field": "supplier", "op": "eq", "value": "rec_0123abcd" } ], "set": { "department": "Facilities" }}| Part | Says |
|---|---|
name |
Lower-case letters, digits, _ and -, unique in the definition. The delivery’s answer and the record’s history name it. |
table |
A table the intake writes. The rule runs on every record the delivery makes for it. |
when |
One to eight conditions, all of which must hold. |
set |
One to eight fields and the value each takes, as the record API takes it for the field’s type. A reference takes the record’s id. |
Each condition is { of, field, op, value }. of says what it reads:
record, the default: the value the mapping gavefieldon the record the rule sets.root: the value on the delivery’s root record, so a line’s rule can test its invoice.read: the text the document held forfieldon this record, before any import rule converted it. Text is compared ignoring case and repeated spaces.
op is eq, neq, in (any of an array of values), isEmpty,
isNotEmpty, contains or startsWith. Values are compared after
references are looked up, as they would be stored.
Rules run in order. A value a rule sets replaces what the mapping gave, and a
later rule can replace it again. A rule cannot set the intake’s file fields, a
child’s link to its parent, or a derived field. Publishing checks that every
field exists and every value fits its field, naming the path of each problem,
such as corrections[0].set.department.
A rule only sets values on the records the delivery makes. To do more, such as notify someone or update other records, use a flow on the record’s creation.
Suggested rules
Section titled “Suggested rules”Give the definition a learning block and the platform studies how reviewers
correct the records the intake makes, then suggests correction rules:
{ "learning": { "minCorrections": 3, "windowDays": 120, "contextFields": ["supplier"] } }| Part | Says |
|---|---|
minCorrections |
How many records corrected the same way make a suggestion, from 2 to 50. 3 when absent. |
windowDays |
How far back a correction counts, from 7 to 730 days. 120 when absent. |
contextFields |
Up to five fields of the root’s table. A value set again and again while one of them agrees is suggested as a rule on it. |
A correction is a change a person makes to a field of a record the intake made, leaving it different from what the delivery gave it. Changes made by an integration, a flow or the platform never count, and only the latest change of a field on a record counts. Two kinds of suggestion come from them:
- Text: the same text read from the document was corrected to the same
value, such as
ACME LTDto the supplier ACME Limited. The rule tests the text read (of: read). The intake must keep the read text as evidence. - Context: the same value was set while a context field held the same
value, such as department
Facilitieson the lines of every Northwind invoice. The rule tests that field on the root (of: root).
Suggestions are refreshed daily, or at once with
POST /intakes/{intakeName}/suggestions/refresh.
GET /intakes/{intakeName}/suggestions lists them, each with its rule and the
corrections it rests on: the record, the value before and after, the text read,
who made the change and when. Evidence on a record you cannot read is counted
but not listed. All of these need intakes:manage.
Nothing changes until you decide:
POST /intakes/{intakeName}/suggestions/{suggestionId}/acceptadds the rule to the draft. Publish the draft to apply it to deliveries.POST /intakes/{intakeName}/suggestions/{suggestionId}/dismissdismisses it. It is not suggested again until its evidence grows byminCorrectionsmore records.
An open suggestion whose corrections age out of the window, or that a rule in the published version or the draft already covers, is withdrawn. Accepted and dismissed suggestions are kept for a year.
Drafts and versions
Section titled “Drafts and versions”Defining an intake needs intakes:manage; reading one needs tables:read.
POST /intakescreates the intake with its first draft. The draft is checked for structure only.PUT /intakes/{intakeName}/draftsaves the draft. Send the draft’supdatedAtasexpectedUpdatedAt; a save over a newer draft is refused withSTALE_RECORD.POST /intakes/{intakeName}/publishchecks the draft against your tables and publishes it as the next version. Each problem names its path in the definition, such asroot.fields[3].to.
Published versions never change. GET /intakes/{intakeName}/versions lists
them, newest first. Deliveries run the published version.
Delivering a document
Section titled “Delivering a document”POST https://api.tessule.com/api/intakes/scanned_invoices/deliveriesAuthorization: Bearer crm_...Idempotency-Key: scan-INV-1042Content-Type: application/jsonThe document arrives one of two ways, never both:
-
Staged, for a large document. Stage the document and the source file on the intake’s two file fields with
POST /tables/{tableId}/fields/{fieldId}/attachments/staged, upload each to its URL, and send both values:{ "files": {"document": { "s3Key": "…", "filename": "scan.json", "mimeType": "application/json", "size": 48213, "uploadedAt": "2026-03-15T14:30:00Z" },"source": { "s3Key": "…", "filename": "scan.pdf", "mimeType": "application/pdf", "size": 91022, "uploadedAt": "2026-03-15T14:30:00Z" } } }The document is kept on the record byte for byte.
-
Inline, for a small document. Send it as
document, with onlyfiles.sourcestaged. The intake keeps it on the record as a JSON file.
The delivery then checks the document, selects and converts each value, looks up references, and writes every record, file and evidence row in one record-graph write. Either all of it is kept or none of it.
The answer
Section titled “The answer”{ "results": [ { "index": 0, "op": "create", "table": "rec_0123abcd", "id": "rec_0123abcd", "ref": "root" } ], "replayed": false, "intake": { "name": "scanned_invoices", "version": 1 }, "unresolved": [ { "index": 0, "field": "supplier", "text": "Acme Plumbing Supplies", "reason": "unmatched" } ], "blanked": [ { "index": 2, "field": "quantity", "text": "approx 3", "reason": "'approx 3' is not a number" } ], "corrected": [ { "index": 1, "field": "department", "rule": "northwind-facilities" } ]}blanked: a value that does not convert to its field’s type is left empty, never guessed, and the delivery goes ahead.unresolved: a reference that matches no single record the caller can read is left empty.corrected: a value a correction rule set, naming the rule. A value a rule sets is no longer listed as blanked or unresolved.
In both cases the evidence row keeps the text that was read, so a reviewer sees what the document said.
A record’s own rules still apply. A required field left empty, or a value a unique field already holds, refuses the whole delivery, naming the operation.
Refusals
Section titled “Refusals”| Status | code |
When |
|---|---|---|
| 400 | DOCUMENT_INVALID |
The document is not one the intake accepts. Each problem names a JSON pointer into the document, such as /ExpenseDocuments. |
| 400 | DOCUMENT_SOURCE |
The document came both staged and inline, or neither. |
| 409 | INTAKE_NOT_PUBLISHED |
The intake has no published version. |
| 409 | INTAKE_DEFINITION_STALE |
Your tables changed since the version was published, and it no longer fits them. Publish a corrected version. |
Nothing is written on a refusal.
Retrying
Section titled “Retrying”Send an Idempotency-Key. A retry with the same key and body answers the first
result with replayed: true and writes nothing, for 24 hours. The same key
with a different body is refused with IDEMPOTENCY_KEY_REUSED.
Testing a mapping
Section titled “Testing a mapping”dryRun: true runs everything, keeps nothing, and adds the record-graph
request the intake built to the answer. draft: true with dryRun: true runs
the draft instead of the published version, to try a change before publishing
it.
Each intake in your OpenAPI spec
Section titled “Each intake in your OpenAPI spec”The per-workspace OpenAPI spec
lists every published intake as an operation of its own: the delivery
endpoint with the intake’s name filled into the path. For a json
intake, the inline document is typed to the published documentSchema, so
a client generated from the spec refuses a document the intake would refuse.
The type follows the published version: it moves when you publish, never when
you save a draft.
Two cases keep an untyped document:
- a
textract-expenseintake, whose document is Textract’s own output; - a
jsonintake whose schema has a$refthat is recursive or points outside the schema, or uses a keyword JSON Schema draft-07 does not define. The operation’s description names what it is and where. The intake still checks every delivery against the full schema.
The typed operation has no draft flag. To dry-run a draft, call
POST /intakes/{intakeName}/deliveries with the name as a parameter.
History
Section titled “History”Every record a delivery makes names the intake and the version in its history, so you can always tell which definition made it. Where a correction rule set a field, the history names the rule beside the field.