ExportFlowDevelopers
Sign inGet API keys

Guides

Documents

How documents are grouped, uploaded and read: what each status means, what an extracted field looks like, and the limits on a file.

Shipments#

A shipment is a set of documents that travel together: a bill of lading, a commercial invoice, a packing list, certificates. Documents are uploaded to a shipment, each is processed on its own, and the shipment is verified by checking its documents against each other.

Every field of a shipment is optional. reference is your own identifier, such as an order number, and you can list shipments by it. The origin and destination countries are ISO 3166-1 alpha-2 codes and the destination port is a UN/LOCODE; a port must belong to the destination country.

shipment = client.shipments.create(reference="PO-7741", origin_country="NG",
                                   destination_country="IN")
for path in ("bl.pdf", "invoice.pdf", "packing_list.pdf"):
    client.documents.upload(file=path, shipment_id=shipment.id)

A shipment belongs to the environment of the key that created it. Usage, charges and webhook events for its documents are attributed to the application that created it.

Uploading#

One file is one document, sent as multipart/form-data in a field named file. Before anything is stored the file is checked (is it really a PDF or an image, can it be opened, how many pages) and scanned for viruses. A refused file is not stored and not charged, and the error says what to do with it.

The upload answers 201 at once. Processing is asynchronous: poll GET /documents/{id}, or subscribe to document.processing.completed.

Saying what a document is#

The type is detected for you. If your software already knows what it is uploading, pass document_type. Your declaration is kept beside the detected type rather than replacing it: declared_type, detected_type with its type_confidence, and document_type, which is the one in use (yours if you declared one, otherwise the detected one).

client.documents.upload(file="invoice.pdf", shipment_id=shipment.id,
                        document_type="commercial_invoice")

Statuses#

Document statuses
StatusMeaningWhat happens next
classifyingStored and scanned. Its type is being worked out.Moves to reading, split or failed.
readingClassified. Its fields are being extracted.Moves to processed or failed.
processedA reading exists. Individual fields may still be unavailable, each with a reason.Final. Fetch the extraction.
failedProcessing stopped. The error field says why.Final until you ask for it to be processed again.
splitThe file held several documents and was split into them.Final. The parts are documents of their own.

processed, failed and split are the finished states. The SDKs’ documents.wait returns on any of them and raises on failed unless you ask it not to.

Processing a failed document again#

A document is processed automatically when it is uploaded, so this is the recovery route. It is safe to call at any time: for a document that is being processed or has already been read it changes nothing and answers queued: false. It never buys the same reading twice.

accepted = client.documents.process(document.id)
print(accepted.queued)        # False if it was already being processed or already read

Bundles#

A single PDF often holds several documents scanned together. When classification finds that, the upload becomes a bundle: its status is split, and each document inside it becomes a document of its own on the same shipment, with parent_document_id pointing at the file it came from.

List the shipment’s documents to find the parts. The parts are what you fetch extractions for; a bundle itself has no fields of its own and is not processed again.

Extracted fields#

GET /documents/{id}/extraction returns the current reading of every field. It is empty until the document is processed.

extraction = client.documents.extraction(document.id)
print(extraction.as_dict())                           # {"bl_number": "MEDU7741203", ...}

for field in extraction.fields:
    print(field.name, field.value or field.unavailable_reason)
What an extracted field carries
FieldMeaning
nameThe field's name, for example bl_number.
valueWhat was read, as text. Null when there is no value.
unavailable_reasonWhy there is no value. Null when there is one.
confidenceHow sure the reading is, when the method reports it. Null otherwise.
pageThe page the value was read from, when known.
methodHow the value was read.
extraction_idIdentifies this reading. Cite it when confirming the field, to keep the link to where the value came from.
A value, or a reason

Every field has exactly one of value and unavailable_reason. A field that could not be read is reported as unavailable with the reason; it is never returned as an empty string and never left out. Treat an unavailable field as unknown, not as blank.

Duplicates#

Uploading the same file to the same shipment twice returns the first document, with duplicate: true. Nothing new is stored, nothing is processed again and nothing is charged. The file is recognised by its content (sha256), not by its name.

This is separate from idempotency, which makes a repeated request safe. Duplicate detection makes a repeated file safe, even when it arrives in a new request with a new key.

Limits#

Limits on an uploaded file
LimitValueIf exceeded
FormatsPDF, PNG, JPEG, TIFF, WebPupload_unrecognised_format
Pages in one file40upload_too_many_pages
File size25 MBupload_too_large
Documents waiting to be processed, per account40too_many_documents_in_progress

The format is decided from the file’s content, never from its name or its declared type. A password-protected or damaged file is refused at upload with its own code. See upload errors and rate limits and quotas.