DIAN REST API uses standard HTTP status codes for REST-level errors and a structured JSON body for application-level errors. Understanding the error hierarchy — Pydantic validation failures, business rule violations enforced by the use case, and DIAN SOAP-layer errors returned by the adapter — helps you build robust integrations that fail fast, log correctly, and recover gracefully from the range of issues that can occur when interacting with Colombia’s DIAN electronic invoicing service.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/farojas85/fast-rest-api/llms.txt
Use this file to discover all available pages before exploring further.
HTTP Status Code Reference
| Code | Meaning | When it occurs |
|---|---|---|
201 Created | Invoice submitted successfully | DIAN accepted the document; track_id and status are populated in the response body |
422 Unprocessable Entity | Request validation failed | A required field is missing, a value has the wrong type, or a Pydantic validator constraint (e.g., gt=0 on cantidad) is violated |
500 Internal Server Error | DIAN submission failed | SOAP timeout, DIAN service rejection, WSDL mismatch, certificate error, or any unhandled exception in the adapter layer |
422 Validation Error
FastAPI automatically returns422 Unprocessable Entity whenever the incoming JSON request body fails Pydantic schema validation. The response body contains a detail array where each element identifies the exact location and nature of the failure.
Standard 422 response shape (FastAPI/Pydantic v2):
Missing Required Field
Ifitems is omitted from the request body:
Business Rule Violation — Mismatched Totals
PedidoLocalCreateRequest passes Pydantic validation even if the totals are arithmetically inconsistent, because Pydantic only validates types and field constraints. The total integrity check is enforced in FacturarPedidoLocalUseCase.execute():
ValueError is raised, FastAPI propagates it as an unhandled exception, resulting in a 500 Internal Server Error. To avoid this, always verify on the POS side that:
500 DIAN Submission Error
When the DIAN SOAP adapter fails — regardless of the underlying cause — the controller returns a500 Internal Server Error with the following structured body (from src/infrastructure/controllers/pedido_local_controller.py):
Adapter-Level Error Cases
The DIAN SOAP adapter surfaces two distinct error categories: 1. Timeout DIAN did not respond within the configured timeout window (30 seconds viahttpx).
2. Generic Exception Any other exception caught during the SOAP call: XML/WSDL parsing errors, TLS handshake failures, SOAP fault responses, network errors, or certificate issues.
error field contains the Python exception class name (e.g., "zeep.exceptions.Fault", "ssl.SSLError") and message contains the exception string.
Cause: WSDL mismatch, malformed XML, invalid or expired certificate, network routing failure.
Remediation: Check the WSDL URL configured in DIAN_WSDL_URL_HABILITACION or DIAN_WSDL_URL_PRODUCCION, verify DIAN’s service status page, and confirm the PFX certificate at DIAN_CERT_PATH is valid and not expired.
Common Error Scenarios
total_factura does not match subtotal + impuestos_totales + propina_voluntaria
total_factura does not match subtotal + impuestos_totales + propina_voluntaria
Error message:Cause: The submitted
total_factura field does not arithmetically equal subtotal + impuestos_totales + propina_voluntaria. This is enforced in FacturarPedidoLocalUseCase.execute() before any DIAN call is attempted.Remediation: Recalculate all totals in your POS system immediately before building the request payload. This is a pre-submission check — do not rely on the API to auto-correct totals. For example:Failed to load the PFX certificate
Failed to load the PFX certificate
When it occurs: At application startup, when
DianSoapAdapter is instantiated and attempts to load the PKCS#12 certificate from disk.Cause: The file at DIAN_CERT_PATH does not exist, is not readable by the application process, or DIAN_CERT_PASSWORD is incorrect.Remediation:- Verify the file path in your
.env:DIAN_CERT_PATH=/absolute/path/to/cert.pfx - Confirm the file is readable:
ls -la $DIAN_CERT_PATH - Confirm the password is correct by testing the certificate independently with OpenSSL:
- Ensure the certificate has not expired.
SOAP Timeout — DIAN does not respond within 30 seconds
SOAP Timeout — DIAN does not respond within 30 seconds
When it occurs: During the Cause: DIAN’s habilitación service has scheduled maintenance windows and can be intermittently slow. Network latency from outside Colombia may also contribute.Remediation: Implement retry logic with exponential backoff in your POS integration layer. A simple strategy:Do not retry indefinitely — log the failure and alert operations if all retries are exhausted.
SendTestSetAsync (habilitación) or production SOAP call, if DIAN’s service does not return a response within the adapter’s configured httpx timeout of 30 seconds.Response body:422 on cantidad — zero or negative quantity
422 on cantidad — zero or negative quantity
Error message:Cause: The Sending
cantidad field on ItemPedidoRequest has a gt=0 Pydantic constraint:0 or any negative integer for item quantity will trigger this validation error before the request reaches the use case.Remediation: Filter out zero-quantity items in your POS system before building the request payload. Only include items with cantidad >= 1.