> For the complete documentation index, see [llms.txt](https://docs.facephi.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.facephi.com/docs.facephi-en/rest-api/midapi-v2/document-services/document-validation.md).

# Document Validation

**Document Validation** is the service that analyzes the identity document (and, optionally, a selfie) and determines whether they are authentic and consistent with each other. The service is integrated as part of the Facephi API ecosystem.

Based on the document (and, if provided, the selfie), the service runs a set of anti-fraud checks and returns a single diagnosis:

* **APPROVED**: the document (and, where applicable, the match with the selfie) passes validation.
* **DECLINED**: an inconsistency, manipulation, or quality/format issue is detected that prevents the document from being validated.
* **DOUBTFUL**: the analysis is inconclusive. The document is neither confirmed as authentic nor rejected, and the decision is left to the consumer. This status only appears in automatic mode.

### Asynchronous nature

Document Validation is an asynchronous service: the call that starts the validation does not wait for the result. It responds immediately with a transaction identifier (`transactionId`) and the consumer obtains the result by polling for status updates.

### Service modes

Document Validation is available in two modes, which are set when the service is configured and cannot be selected per request:

* **Automatic**: the diagnosis is issued entirely by Facephi’s anti-fraud engine. When the analysis is inconclusive, the transaction ends with `diagnostic = DOUBTFUL` and its corresponding `rejectionReason` .
* **Hybrid**: when the initial analysis is inconclusive, the case undergoes an additional escalated verification before a decision is made. The final diagnosis is **always `APPROVED` or `DECLINED`: this mode does not return `DOUBTFUL`**. Reason codes 600 to 603 only appear in this mode.

If you’re not sure which mode your integration uses, contact support.

### Integration Flow

The initial setup (token, operation, and asset upload) is common to all services that work by reference and is described in [Common Flow](https://docs.facephi.com/docs.facephi-en/rest-api/midapi-v2/flujo-comun.md). From there:

1. Complete the preceding steps in the [common flow](https://docs.facephi.com/docs.facephi-en/rest-api/midapi-v2/flujo-comun.md), including [uploading the assets](https://docs.facephi.com/docs.facephi-en/rest-api/midapi-v2/document-services/document-validation/subida-de-assets.md) for the document and, optionally, the selfie.
2. [Start the validation](https://docs.facephi.com/docs.facephi-en/rest-api/midapi-v2/document-services/document-validation/iniciar-validacion.md) by sending the `fileKeys` you obtained, unchanged, with the `operationId` in the `operation-id`header. The service responds immediately with a `transactionId`.
3. [Check the status](https://docs.facephi.com/docs.facephi-en/rest-api/midapi-v2/document-services/document-validation/consultar-estado.md) of the transaction by polling until a terminal status is reached.

```mermaid
sequenceDiagram
    actor C as Consumer
    participant API as Middleware API v2

    Note over C,API: Prerequisites: token, operation, and asset upload (see Common Flow)

    C->>API: POST /document/validate (fileKeys + operation-id)
    API-->>C: 202 transactionId, status PROCESSED

    loop Polling until terminal status
        C->>API: GET /document/validate/{transactionId}
        API-->>C: status IN_PROGRESS
    end

    C->>API: GET /document/validate/{transactionId}
    API-->>C: COMPLETED + diagnostic + rejectionReason + diagnostics[] + ocr
```

The recommended polling interval is in [Best Practices](https://docs.facephi.com/docs.facephi-en/rest-api/midapi-v2/document-services/document-validation/buenas-practicas.md), and the details of the terminal response are in [Result Response](https://docs.facephi.com/docs.facephi-en/rest-api/midapi-v2/document-services/document-validation/respuesta-de-resultado.md).

{% hint style="info" %}
Document Validation works **exclusively by reference**: it does not accept asset content inline. The reference model common to the entire API is in [Storage](https://docs.facephi.com/docs.facephi-en/rest-api/midapi-v2/storage.md).
{% endhint %}

{% hint style="warning" %}
**Route changes.** Document validation is now available under `/document/validate`. The previous routes are still supported to avoid breaking existing integrations, but they are deprecated and will no longer be documented:

| Previous route             | Current route                            |
| -------------------------- | ---------------------------------------- |
| `POST /daf/validate`       | `POST /document/validate`                |
| `GET /daf/{transactionId}` | `GET /document/validate/{transactionId}` |
| `POST /daf/fraud-report`   | `POST /document/validate/fraud-report`   |

The contract has not changed: same headers, same request body, and same responses. Only the route has changed.
{% endhint %}
