Documents API
This API allows managing documents in the system. It provides endpoints to create, read, update, and delete documents, as well as to handle their attachments.
The Document Object
The Document object represents a document in the system.
Attributes
| Attribute | Description | Type |
|---|---|---|
| id | Unique identifier of the document | String |
| borrowerId | ID of the borrower associated with the document | String |
| key | Key identifying the type of document | String |
| label | Descriptive label of the document | String |
| value | Value associated with the document | Any |
| tags | Tags associated with the document | Array of String |
| createdAt | Document creation date and time | String (ISO 8601) |
| updatedAt | Last update date and time | String (ISO 8601) |
| hasAttachments | Indicates if the document has attachments | Boolean |
| processingStatus | Status of the last document processing run after manual reviews: valid, invalid or needs_review. null when the document was never processed | String or null |
Available Operations
Create a New Document
Creates a new document in the system.
Input Parameters
| Parameter | Description | Type | Required |
|---|---|---|---|
| borrowerId | ID of the borrower associated with the document | String | Yes |
| key | Key identifying the type of document | String | Yes |
| value | Value associated with the document | Any | No |
| tags | Tags associated with the document | Array of String | No |
Request Example
Successful Response
Update a Document
Updates an existing document.
Path Parameters
| Parameter | Description |
|---|---|
| :document_id | ID of the document to update |
Input Parameters
| Parameter | Description | Type | Required |
|---|---|---|---|
| key | New document key | String | No |
| value | New value associated with the document | Any | No |
| tags | New tags associated with the document | Array of String | No |
Request Example
Successful Response
Returns the updated Document object.
Retrieve a Document
Retrieves the information of a specific document.
Path Parameters
| Parameter | Description |
|---|---|
| :document_id | ID of the document to retrieve |
Successful Response
Returns the complete Document object.
Delete a Document
Deletes a document from the system.
Path Parameters
| Parameter | Description |
|---|---|
| :document_id | ID of the document to delete |
Successful Response
Status code 204 (No Content) if the deletion was successful.
List Documents
Retrieves a paginated list of documents with filtering and sorting options.
Query Parameters
| Parameter | Description | Type |
|---|---|---|
| borrower-id | Filter by borrower ID | String |
| search | Text to search in documents | String |
| page | Page number (default: 1) | Integer |
| per-page | Items per page (default: 10) | Integer |
| key | Filter by document key | String |
| sort-by | Field to sort by | String |
| sort-direction | Sorting direction (asc or desc) | String |
Successful Response
Paginated list of Document objects.
Add an Attachment to a Document
Adds a new attachment to an existing document.
Path Parameters
| Parameter | Description |
|---|---|
| :document_id | ID of the document to add attachment to |
Input Parameters
| Parameter | Description | Type | Required |
|---|---|---|---|
| url | URL of the attached file | String | Yes |
| label | Descriptive label of the attachment | String | No |
| fileExtension | File extension | String | No |
| metadata | Metadata associated with the attachment | Object | No |
Request Example
Successful Response
Status code 201 (Created) if the attachment was successfully added.
Upload an Attachment to a Document
Uploads a file as an attachment to an existing document.
Path Parameters
| Parameter | Description |
|---|---|
| :document_id | ID of the document to upload attachment to |
Form Parameters
| Parameter | Description | Type | Required |
|---|---|---|---|
| file | File to upload | File | Yes |
| label | Descriptive label of the attachment | String | No |
| metadata | Metadata in JSON format | String | No |
Successful Response
Status code 201 (Created) if the file was successfully uploaded.
Retrieve Attachments of a Document
Retrieves the list of attachments associated with a document.
Path Parameters
| Parameter | Description |
|---|---|
| :document_id | ID of the document to retrieve attachments from |
Successful Response
List of Attachment objects associated with the document.
Delete an Attachment from a Document
Deletes a specific attachment from a document.
Path Parameters
| Parameter | Description |
|---|---|
| :document_id | ID of the document |
| :attachment_id | ID of the attachment to delete |
Successful Response
Status code 204 (No Content) if the attachment was successfully deleted. The page images and crops kept by document processing for that attachment are deleted with it.
Process a Document
Reads attachments of a document with the processing definition of its data model, extracting and validating what the
definition asks for, and stores the results. It is what the Extract data, Validate or Extract and validate
button of a file does in the Hub, which always sends that one file in attachmentIds. The
Document Processing guide explains what is computed and how to set it up.
Requires the borrowers.write permission. The data model whose key is the document's key must have a
processing definition with enabled: true.
Path Parameters
| Parameter | Description |
|---|---|
| :document_id | ID of the document to process |
Input Parameters
| Parameter | Description | Type | Required |
|---|---|---|---|
| attachmentIds | Attachments to process, up to 20. Absent or empty: every attachment of the document | Array of String | No |
Request Example
The call waits for the run to finish, which can take a few minutes for files with many pages; allow up to five
minutes before timing out. Only one run per document at a time: a second one while the first is running gets 409
with DOCUMENT_PROCESSING_IN_PROGRESS.
Attachments that are not PDF, JPG, JPEG, PNG, WEBP, HEIC or HEIF are not read; their result is stored with outcome
unsupported and they do not count toward the document's status. Attachments that were not selected keep their
earlier results and their reviews, as long as they were produced with the current definition, and rules that compare
files take them into account. That includes attachments that were never read (too_large, failed, unreadable,
unsupported): reading one attachment again does not drop another one that was ignored. Results of other attachments
produced with an earlier definition are not counted until those attachments are read again.
A run replaces the results and the evidence of the attachments it read, the reviews of those attachments, and every review of a document validation.
Successful Response
The same body as Get the Processing Results of a Document, after the run was stored.
Get the Processing Results of a Document
Returns the stored results of a document and of each of its attachments, with signed links to the page images and crops.
Requires the bc.attachments.read permission, because the response gives access to images of the files.
Path Parameters
| Parameter | Description |
|---|---|
| :document_id | ID of the document |
Successful Response
Abridged: one attachment, two of its four fields and one of its two validations.
How to read it:
summaryisnullwhen the document was never processed.statusis what the run produced andeffectiveStatusis the status after manual reviews; use the effective one.resultsCurrent: falsemeans the definition changed after the run, andattachmentsChanged: truemeans attachments were added or removed since. Either way, run the document again.revisiongoes up with every run and every review, andmodelCallscounts the calls to the AI model in the last run.attachments[].processingisnullfor an attachment that was never processed.outcomeisprocessed,unclassified(matched no type),unreadable,failed(the AI provider did not answer),too_large(more than 30 pages) orunsupported(a file type that is not read). When it is notprocessedorunclassified,error.codesays why:CONTENT_NOT_RESOLVED,UNREADABLE_FILE,TOO_MANY_PAGES,AI_PROVIDER_UNAVAILABLE,AI_PROVIDER_RATE_LIMITED,AI_PROVIDER_TIMEOUT,AI_PROVIDER_REJECTED,BUDGET_EXHAUSTEDorUNEXPECTED. Atoo_largeorfailedattachment is leftneeds_reviewuntil someone reviews its type: approved, it isexcluded(the Hub's Ignore this file); rejected, it isinvalidwithtype_rejected(Mark as not valid).pageCountis the number of pages in the file. Fortoo_largeit is the real count, so you can tell how far over the 30-page limit it is. It isnullwhen nothing was rendered (an unreadable file, a download that failed) or for results stored before this field existed.acceptedTypessays which needed types are covered:satisfiedByandpendingBylist, per type, the valid attachments and those still to review.unreadFileslists the attachments that were not read and have no type (too_large,failed, andunclassifiedwithout a review): they could be any type, so they keep the documentneeds_reviewwithaccepted_type_unconfirmedinstead of making itinvalid.invalidBylists, per type, the attachments of that type that areinvalid; a type that only has those is reported asaccepted_type_invalidand not asaccepted_types_missing.missingTypeslists the types with no valid or pending attachment.partial: truemeans extraction stopped before trying every field, so some fields may be missing only because they were not asked for again.warningsthen includesEXTRACTION_INCOMPLETE. Other warnings areEVIDENCE_SKIPPED(no page image could be made) andOCR_CHECK_SKIPPED(the run was out of time for the cross-check).- Fields:
valueis the text as the model copied it andtypedValuethe parsed value (nullwhen missing or unparseable).formatFlagscan holdambiguous_separator,fraction_in_integer,ambiguous_day_month,two_digit_year,partial_date,invalid_date,out_of_rangeorunparseable.confidenceBreakdown.ocrSourcesays what the value was compared with:text_layer(the PDF's own text),tesseract(OCR of the box),document_text,skippedornull(not computable).boundingBoxis on a 0 to 1000 scale of the page image. - Links in
pages[].urlandevidenceexpire after 60 minutes. Request the results again to get new ones.evidenceis always an object:pageUrlorcropUrlisnullwhen that image was not stored. runningis{"startedAt": "..."}while a run is in progress.
The extraction and validation blocks
Each attachment also carries two flat blocks. They are derived at read time from the stored result and the
current definition; nothing extra is stored. definition.mode says which ones apply: extraction (only fields to
extract), validation (only conditions) or both, and null when the data model has no definition. A block is null
when the mode has no part of that kind, or when the attachment has no result.
An electricity bill read in mode both, with one condition that failed:
extraction:
valueshas one key per field to extract (rows withoutpurpose, or withextractionorboth), in the order of the definition. The value is the parsed value (typedValue) when the field isokorneeds_reviewafter reviews, andnullwhen it ismissing,waivedor was rejected. A file that was not read or not recognized has emptyvaluesandevidence.evidencehas, for each field that was read, the value as printed (value), its status after reviews, its confidence andbasis(valuewhen the value was checked against the page,quotewhen the sentence the model quoted was checked instead; see the guide), the page, the box, the text it relies on (sourceText) and the signed links to the page and the crop.statusisexcluded(someone ignored the file),not_read(too_large,failed,unreadableorunsupported),not_recognized(it matched no type, or a reviewer rejected its type),needs_review(the reading was partial, a field needs review, or the type is doubtful) orextracted. A missing optional value is justnull.
validation:
statusis the attachment's status after reviews (valid,invalid,needs_review,excluded), andvalidistrueorfalsefor the first two andnullfor the other two.reasonsare its reasons after reviews.rowshas one entry per condition (rows withpurposevalidationorboth), in the order of the definition: what wasexpected, what was read (readparsed,readTextas printed, bothnullwhen nothing usable was read), the field's status, the condition'sstatus(pass,fail,inconclusive) andpassed(true,false,null), thereasonwhen it is inconclusive, and the same location and evidence keys asextraction.otherRuleslists the type's own validations from Advanced options, with theirstatusandpassed.- A file that was not read or not recognized has empty
rows; itsstatusandreasonssay why.
When the result was produced with an earlier definition (resultsCurrent: false), both blocks say "current": false,
keep only the fields the result still has, and every expected is null.
In summary, extractionStatus is extracted when every evaluated attachment that is not excluded is extracted,
needs_review otherwise, and null when the mode has no fields to extract. validation is
{"status": ..., "valid": ...} for the document, or null when the mode has no conditions.
In mode extraction the attachment and document statuses are still computed, but they are not a verdict: nothing
was validated. Show extraction.status instead.
Review a Processing Result
Approves or rejects one result that the run could not decide. The reviewer's email and the time are stored with the reason, and the statuses of the attachment and the document are recomputed.
Requires the borrowers.write permission.
Path Parameters
| Parameter | Description |
|---|---|
| :document_id | ID of the document |
Input Parameters
| Parameter | Description | Type | Required |
|---|---|---|---|
| target.attachmentId | The attachment. Must be null for documentValidation | String | Yes |
| target.kind | field, validation, logic, documentType or documentValidation | String | Yes |
| target.key | Key of the field, validation or logic rule. Ignored for documentType | String | Yes, except for documentType |
| decision | approved or rejected | String | Yes |
| reason | Why, 1 to 500 characters | String | Yes |
What can be reviewed: a field that needs review, or a required field that is missing; an inconclusive validation,
document validation or logic rule; the type of an attachment that is unclassified or whose type confidence is low;
and the type of an attachment that was never read (too_large, failed). For those two outcomes, approved makes
the attachment excluded and rejected makes it invalid with type_rejected. unreadable and unsupported
attachments cannot be reviewed (PROCESSING_REVIEW_TARGET_NOT_REVIEWABLE).
A condition that is inconclusive is reviewed as kind: "validation" with key: "__expected_<field key>"; a doubtful
value of that row, as kind: "field" with the field key. The guide's "Manual review" section describes what each
decision changes.
Request Example
Successful Response
The same body as Get the Processing Results of a Document. Reviewing a
field or a type re-evaluates the rules that depend on it with the date of the original run; in the example, vigente
becomes pass and the attachment and the document become valid. The new review appears first in reviews:
reviewer.email is null when the review was made with a machine-to-machine token. supersededAt and
supersededBy are filled when a newer review of the same item or a new run replaced this one.
Processing errors
Errors of the three endpoints above carry an errorSubCode in details. When a run fails, nothing is stored.
| Status | errorSubCode | When | Retry? |
|---|---|---|---|
| 404 | The document does not exist | No | |
| 422 | DOCUMENT_PROCESSING_NOT_CONFIGURED | The document's data model has no processing definition, or it is disabled | No |
| 422 | DOCUMENT_HAS_NO_ATTACHMENTS | The document has no attachments | No |
| 422 | PROCESSING_ATTACHMENT_NOT_FOUND | An id in attachmentIds is not an attachment of the document (details.attachmentIds) | No |
| 422 | DOCUMENT_PROCESSING_TOO_MANY_ATTACHMENTS | More than 20 attachments selected | No |
| 422 | DOCUMENT_PROCESSING_NO_SUPPORTED_ATTACHMENTS | None of the selected attachments is a file type that can be read | No |
| 422 | DOCUMENT_PROCESSING_TOO_MANY_RESULTS | The document has more than 200 processed attachments to evaluate together (details.maxResults). Applies to runs and to reviews that re-evaluate rules | No |
| 409 | DOCUMENT_PROCESSING_IN_PROGRESS | Another run of the same document is in progress | Yes, when it finishes |
| 422 | DOCUMENT_NOT_PROCESSED | Review: the document has no results | No |
| 409 | DOCUMENT_PROCESSING_STALE | Review: the result was produced with an older definition | Run the document again first |
| 422 | PROCESSING_REVIEW_TARGET_NOT_FOUND | Review: the item does not exist | No |
| 422 | PROCESSING_REVIEW_TARGET_NOT_REVIEWABLE | Review: the item is not undecided | No |
| 503 | DOCUMENT_PROCESSING_PROVIDER_UNAVAILABLE | The AI provider is not answering (details.providerErrorSubCode) | Yes |
| 503 | DOCUMENT_PROCESSING_TIMEOUT | The processing service did not answer in time | Yes |
| 503 | DOCUMENT_PROCESSING_SERVICE_UNREACHABLE | The processing service could not be reached | Later |
| 503 | DOCUMENT_PROCESSING_FAILED | The processing service failed | Yes |
| 503 | DOCUMENT_PROCESSING_REJECTED | The processing service rejected the request. This is a problem on our side, not with your request | No; contact support |
A review of a field or a type also gets 503 when its rules cannot be re-evaluated; the review is not stored. A
review of the type of an attachment that was never read (too_large, failed) re-evaluates nothing, so it does not
get this error.
Error Handling
The API may return the following error codes:
| Code | Description |
|---|---|
| 400 | Bad Request |
| 401 | Unauthorized |
| 403 | Forbidden |
| 404 | Not Found |
| 409 | Conflict (see Processing errors) |
| 422 | Unprocessable Entity (see Processing errors) |
| 500 | Internal Server Error |
| 503 | Service Unavailable (see Processing errors) |
Errors will include a descriptive message in the response body.