Building reliably
Errors
Every failure has a stable code to branch on and a message written for a person. This page lists every code the API can answer with.
The error envelope#
An error is a JSON object with one member, in the same shape whatever went wrong:
{
"error": {
"code": "not_confirmed",
"message": "Confirm what the documents say before checking them. If extraction misread a field, every finding computed from it would be wrong."
}
}codeis machine-readable and stable. Branch on it. A code is never renamed within version 1; new codes can be added.messageis a sentence for a person and says what to do. It can be reworded at any time, so never match on it. It is safe to show to your own users.
Every response, successful or not, carries an x-request-id header. Log it, and quote it to MeerTech when you ask about a request. The same id is beside the request in the console’s request log.
A request that does not match the endpoint’s schema (an identifier that is not a UUID, a field that is too long, an unknown field, a missing body) is answered 422 with the code invalid_request, in the same envelope. The message names the first field at fault.
Handling errors#
With an SDK, catch the error type and read its code. Over HTTP, read the status and the code. Either way the decision is the same three-way one: fix the request, wait and retry, or ask a person to do something.
import time
import exportflow
try:
client.verifications.create(shipment_id)
except exportflow.ConflictError as error:
if error.code == "not_confirmed":
... # ask the user to confirm the record
except exportflow.QuotaExceededError:
... # the month's allowance is used up
except exportflow.RateLimitError as error:
time.sleep(error.retry_after or 5)
except exportflow.APIConnectionError:
... # safe to retry later| Status | Retry? | What it means |
|---|---|---|
| 400, 422 | No | The request is wrong. Fix it; sending it again unchanged will fail again. |
| 401, 403 | No | The key is not valid, or may not do this. |
| 404 | No | No such resource in this key's organisation and environment. |
| 409 | Depends | The resource is not in a state that allows this. request_in_progress and idempotency_conflict are retried; not_confirmed needs a person. |
| 426 | No | The SDK is too old. Upgrade it. |
| 429 | Depends | rate_limited: wait for Retry-After, then retry. The others are an allowance used up, and waiting a few seconds will not help. |
| 5xx | Yes | ExportFlow's fault. Retry with backoff and the same Idempotency-Key. |
What the SDKs raise#
Both SDKs raise the same set of error types, with the same names. Every one carries the API’s code, the HTTP status and the request id.
| Error | HTTP | Meaning |
|---|---|---|
AuthenticationError | 401 | Key missing, wrong, revoked or expired |
PermissionDeniedError | 403 | Missing scope, suspended account, disabled application, network not allowed |
NotFoundError | 404 | No such resource in this organisation and environment |
ConflictError | 409 | Not possible in the current state, for example not_confirmed |
InvalidRequestError | 400, 422 | The request is wrong; do not retry |
RateLimitError | 429 | Slow down; see the retry-after value |
QuotaExceededError | 429 | Allowance or spending limit reached for the period. Not a RateLimitError (since SDK 1.1) |
SDKVersionUnsupportedError | 426 | Upgrade the SDK |
ServerError | 5xx | ExportFlow's fault; retried automatically |
APIConnectionError, APITimeoutError | none | The API could not be reached, or did not answer in time |
The SDKs retry connection failures, timeouts, rate_limited, request_in_progress, idempotency_conflict and 5xx for you, twice by default, with backoff, sending the same idempotency key each time. When the API asks for a longer wait than the client allows (60 seconds by default: max_retry_wait in Python, maxRetryWait in TypeScript), the error is raised at once instead of blocking the call.
Every object an SDK call returns carries the request id of that call (request_id in Python, requestId in TypeScript), not only errors.
Code reference#
Grouped by where the error comes from. Within a group, in the order you are likely to meet them.
Authentication and access#
Decided before the request reaches a route. A missing, malformed, unknown, revoked or expired key all receive the same answer on purpose: saying which would tell somebody guessing keys that one of their guesses was once real.
| Code | Status | Meaning | What to do |
|---|---|---|---|
invalid_api_key | 401 | No key was sent, or the key is not valid: malformed, unknown, revoked or expired. | Send Authorization: Bearer followed by a current key. Check the key's status in the console. |
insufficient_scope | 403 | The key is valid but was issued without the scope this call needs. The message names the scope. | Use a key that holds the scope, or issue one that does. |
account_suspended | 403 | The organisation's account is suspended. | Contact MeerTech. The reason is shown in the console overview. |
application_disabled | 403 | The application the key belongs to is disabled. | Enable the application in the console. |
application_owner_unavailable | 403 | The member who owns the application is no longer active, so its keys are refused. | An owner of the organisation assigns the application to another member in the console. |
ip_not_allowed | 403 | The account has an IP allowlist and the request came from an address outside it. | Call from an allowed network, or ask MeerTech to change the allowlist. |
sdk_version_unsupported | 426 | The request came from an ExportFlow SDK older than the oldest supported version. | Upgrade the SDK. Requests that do not come from an SDK are never refused this way. |
Rate limits and quotas#
All answered 429, and they mean different things. Only rate_limited goes away by waiting a few seconds.
| Code | Status | Meaning | What to do |
|---|---|---|---|
rate_limited | 429 | Too many requests in the current one-minute window for the key, the application or the organisation. | Wait for the number of seconds in Retry-After, then repeat the request. The SDKs do this. |
quota_exceeded | 429 | The account has used its allowance for the period on this meter. The message gives the allowance and the reset date. | Wait for the reset date, or ask MeerTech about a larger plan. Retrying sooner will not help; afterwards, use a new Idempotency-Key. |
spend_limit_reached | 429 | The account has reached its spending limit for the period. | Wait for the reset date, or contact MeerTech to raise the limit. |
too_many_documents_in_progress | 429 | The account already has the maximum number of documents waiting to be processed. | Upload again, with a new Idempotency-Key, when some have finished. Poll, or wait for document.processing.completed. |
Idempotency#
From the idempotency check that every POST, PUT, PATCH and DELETE passes through.
| Code | Status | Meaning | What to do |
|---|---|---|---|
idempotency_key_required | 400 | A request that changes something was sent without an Idempotency-Key header. | Send the header. The SDKs set it for you. |
idempotency_key_too_long | 400 | The Idempotency-Key is longer than 255 characters. | Use a shorter key. |
idempotency_key_reused | 409 | The key was already used for a different request: another method, path or body. | Use a new key for a new request. This is a bug in the caller, not a transient fault. |
request_in_progress | 409 | The first request with this key has not finished yet. | Wait briefly and repeat the request with the same key. The SDKs do this. |
idempotency_conflict | 409 | The first request with this key was released between two checks. Rare. | Repeat the request with the same key. |
Not found#
A resource that exists in the other environment, or in another organisation, is answered exactly like one that does not exist.
| Code | Status | Meaning | What to do |
|---|---|---|---|
shipment_not_found | 404 | No such shipment in this key's organisation and environment. | Check the identifier, and that the key is for the environment the shipment was created in. |
document_not_found | 404 | No such document in this key's organisation and environment. | Check the identifier and the key's environment. |
verification_not_found | 404 | No such verification in this key's organisation and environment. | Check the identifier and the key's environment. |
document_not_on_shipment | 404 | A confirmation names a document that is not on this shipment. | Use a document_id from this shipment's own record. |
run_not_found | 404 | No such verification in this key's organisation and environment. | Check the identifier and the key's environment. Same meaning as verification_not_found. |
webhook_endpoint_not_found | 404 | No such webhook endpoint on this key's application. | List the application's endpoints and use an identifier from that list. |
Malformed requests#
From checking a request against the endpoint's schema, before anything else runs.
| Code | Status | Meaning | What to do |
|---|---|---|---|
invalid_request | 422 | The request does not match the endpoint's schema: a missing or unknown field, a value too long, an identifier that is not a UUID. The message names the first field at fault. | Correct the field the message names. Do not retry unchanged. |
Shipments#
From creating a shipment.
| Code | Status | Meaning | What to do |
|---|---|---|---|
invalid_shipment | 422 | A field of the shipment is not acceptable. The message says which and why. | Correct the field. Do not retry unchanged. |
port_without_country | 422 | A destination port was given with no destination country. | Send destination_country with destination_port. |
port_not_in_country | 422 | The destination port is not a port in the destination country. | Send a UN/LOCODE that belongs to the destination country. |
Uploads#
A file is checked before it is scanned or stored, and a refused file is not stored and not charged. The message always says what to do with the file.
| Code | Status | Meaning | What to do |
|---|---|---|---|
upload_empty | 400 | The uploaded file has no content. | Send the file in a multipart field named file. |
upload_too_small | 400 | The file is under 32 bytes, too small to be a document. | Check that the whole file was sent. |
upload_too_large | 400 | The file is larger than 25 MB. | Split or compress the file. |
upload_unrecognised_format | 400 | The content is not a PDF, PNG, JPEG, TIFF or WebP file. The content decides, not the file name. | Convert the file to PDF or a supported image. |
upload_declared_type_mismatch | 400 | The part's Content-Type says one format and the content is another. | Send the Content-Type the content really is, or leave it out. |
upload_password_protected | 400 | The PDF is password-protected and cannot be read. | Save a copy without the password and upload that. |
upload_unreadable_pdf | 400 | The PDF is damaged and cannot be opened. | Export or scan the document again. |
upload_unreadable_image | 400 | The image is damaged and cannot be opened. | Take the photograph again, or upload a PDF. |
upload_too_many_pages | 400 | The file has more than 40 pages. | Split it into the separate documents it contains and upload those. |
upload_infected | 400 | The virus scanner rejected the file. | Do not retry with the same file. |
scanner_unavailable | 503 | The file could not be scanned, so it was not stored. | Retry shortly with the same Idempotency-Key. |
Records and verification#
From confirming a shipment's record and starting a verification.
| Code | Status | Meaning | What to do |
|---|---|---|---|
invalid_confirmation | 422 | A confirmed field is not acceptable. The message says which and why. | Correct the confirmation. Do not retry unchanged. |
source_extraction_not_on_shipment | 422 | A confirmation cites a reading that does not belong to this shipment's documents. | Cite an extraction_id from this shipment's own record. |
not_confirmed | 409 | Verification was requested before the shipment's record was confirmed. | Show the record to a person, send their confirmation, then start the verification. |
no_documents | 409 | The shipment has no documents, so there is nothing to read or verify. | Upload the shipment's documents first. |
document_busy | 409 | The document is being processed; it cannot be processed again until that finishes. | Wait for document.processing.completed or failed, then try again. |
document_is_bundle | 409 | The document was split into the documents it held, so it is not processed itself. | Act on its parts: the documents whose parent_document_id is this one. |
no_rule_set | 409 | No rule set is published, so a verification has nothing to check against. | This is on ExportFlow's side. Retry later, and tell MeerTech if it persists. |
Webhook endpoints and usage#
From registering a webhook endpoint and reading usage.
| Code | Status | Meaning | What to do |
|---|---|---|---|
invalid_webhook_url | 422 | The URL cannot be a webhook endpoint: not https, no host name, credentials in the URL, or an address that is not reachable from the internet. | Use a public https URL with no user name or password in it. |
unknown_event_type | 422 | One or more event types are not ones ExportFlow sends. The message lists them. | Subscribe only to the event types in the webhooks guide. |
invalid_period | 422 | The usage period is not a month written YYYY-MM. | Send a period such as 2026-11, or leave it out for the current month. |
Server errors#
ExportFlow's fault. Safe to retry with the same Idempotency-Key: a 5xx never uses the key up.
| Code | Status | Meaning | What to do |
|---|---|---|---|
internal_error | 500 | The request could not be completed. | Retry with backoff. If it persists, send MeerTech the request id. |
document_unreadable | 502 | The stored file could not be read back to process it. | Retry with backoff. If it persists, send MeerTech the request id. |