Get started
Quickstart
Upload a document, read what was extracted from it, confirm it and verify the shipment. Everything here runs in the sandbox, where nothing is charged.
Before you start#
- Create a developer account, or sign in if your organisation already has one.
- In the console, create an application and issue a key for the sandbox environment. It begins
exfk_test_. The secret is shown once: copy it when it appears. - Have one trade document to hand as a PDF, PNG, JPEG, TIFF or WebP file of at most 40 pages.
A sandbox key runs the same pipeline as production on separate data. Sandbox usage is measured, so you can see it in the console, and it is never charged. Move to a production key, which begins exfk_live_, when your integration works.
1. Install an SDK#
The Python SDK installs from PyPI and the TypeScript SDK from npm.
pip install exportflowPython 3.9 or later; Node.js 18 or later. Calling the HTTP API directly needs nothing installed: choose the curl tab in the samples below. See SDKs for how the packages are distributed and configured.
2. Authenticate#
Send the key as a bearer token. Ask the API who the key is: the answer names your organisation, the application and the environment, and proves the key works.
from exportflow import ExportFlow
client = ExportFlow(api_key="exfk_test_...") # or set EXPORTFLOW_API_KEY
identity = client.me()
print(identity.organisation_name, identity.environment) # ... sandboxKeep the key in an environment variable or a secret store, never in source control and never in code that runs in a browser. A 401 with the code invalid_api_key means the key was not sent, or is not a current key.
3. Upload a document#
A document belongs to a shipment. The SDKs create a shipment for you when you do not name one; over HTTP you create it first. The upload returns at once with the document in the classifying state, and processing carries on in the background.
# The document is scanned, stored and queued for processing.
# With no shipment_id, a shipment is created for it.
document = client.documents.upload(file="bill_of_lading.pdf")
# Wait for processing (or use a webhook).
document = client.documents.wait(document.id)
print(document.status, document.document_type) # processed bill_of_ladingA document moves through classifying and reading to processed, or to failed with the reason in error. Polling every two seconds is what the SDKs’ wait helpers do; a webhook avoids polling altogether.
4. Read what was extracted#
Every field comes back with a value or with the reason there is none. A field is never silently missing: unavailable_reason says whether the document did not show it, or it could not be read.
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)5. Confirm, then verify#
Verification refuses to start until the shipment’s record has been confirmed, with the code not_confirmed. This is deliberate. If a field was misread, every finding computed from it would be wrong. In a real integration you show your user what was read and send what they confirm; here one field is confirmed by hand.
# Confirm what the documents say, then verify the shipment.
client.records.confirm(document.shipment_id, {"port_of_discharge": "NHAVA SHEVA"})
verification = client.verifications.create(document.shipment_id)
verification = client.verifications.wait(verification.id)
for finding in verification.findings:
print(finding.severity, finding.message)Each finding has a severity. Read Verification before you present findings to a user: two of the five severities mean a check did not run, and must not be shown as a pass.
What to do next#
- Replace polling with webhooks.
- Handle errors by code, and respect rate limits.
- Watch the requests arrive in the request log and your usage in the console.
- When the integration works in the sandbox, issue a production key. Nothing else changes: the address, the calls and the responses are the same.