> 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/identity-api/identity-api-reference/onboarding/ocr/extract-document-data-web.md).

# Extract Document Data Web

This service returns all the data extracted from an identification document by applying OCR to the MRZ code, PDF, barcode, and fields visible in other areas of the document, according to the model defined for each country. For passports, OCR is applied exclusively to the MRZ code due to its standardized format.

### Integration

This service is used for implementations of the **SelphID Web Widget** or to submit open images from any platform. When using the SelphID Web widget, the images generated by the widget are obtained from an array of images.

### Endpoint

```
POST /services/extractDocumentDataWeb
```

### Headers

| Name          | Type   | Required | Description                                                |
| ------------- | ------ | -------- | ---------------------------------------------------------- |
| **x-api-key** | string | **Yes**  | Authorization API key for access.                          |
| **family**    | string | No       | Value: **OnBoarding**. Required with the Tracking service. |

{% hint style="info" %}
All calls to the Tracking Endpoints with **Identity Platform** must include the `family`.
{% endhint %}

### Request body

**Content-Type:** `application/json`

#### Parameters

| Parameter              | Type    | Required | Description                                                                                                                                                               |
| ---------------------- | ------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `tokenFrontDocument`   | string  | **Yes**  | Image encoded in **Base64** of the front side of the document, with the MIME type header removed.                                                                         |
| `tokenBackDocument`    | string  | No       | Image encoded in **Base64** of the back side of the document, with the MIME type header removed.                                                                          |
| `countryCode`          | string  | **Yes**  | Country code in [**ISO 3166-1 alpha-3**](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3). For passports, only `tokenFrontDocument` with `countryCode` set to **"PSP"**. |
| `decompose`            | boolean | No       | Indicates whether to obtain the facial image present in the document and a signature crop. (\*) Check with the Latam Support team for enabled countries.                  |
| `tracking`             | object  | No       | Object representing the required tracking information.                                                                                                                    |
| `tracking.extraData`   | string  | No       | Token generated by the SDK Mobile/Web. Contains tracking information tokenized with the Platform.                                                                         |
| `tracking.operationId` | string  | No       | Operation identifier generated by the SDK Mobile/Web.                                                                                                                     |

#### Example Request

```json
{
  "tokenFrontDocument": "BAMBAQLNHJoWGPjfeuDIzDXdZuP...",
  "tokenBackDocument": "BAMBAQLNHJoWGPjfeuDIzDXdZuP...",
  "countryCode": "ECU",
  "decompose": false,
  "tracking": {
    "extraData": "BQABAQG2gBNjuHN4kLmPqYf7R...",
    "operationId": "123e4567-e89b-12d3-a456-426614174000"
  }
}
```

{% hint style="warning" %}
**Maximum request size: 6 MB.** The Base64 images (`tokenFrontDocument` and `tokenBackDocument`) count toward this limit together, with \~33% overhead compared to the original files (maximum total original file size of \~4.5 MB). Compressed JPEG images of 1–2 MB each at most are recommended. If the limit is exceeded, the gateway responds `413` without processing the request. See [Request size limit](https://docs.facephi.com/pages/bc7bee9358079d52bafa44ad281828eb424e96fe#l%C3%ADmite-de-tama%C3%B1o-de-la-solicitud).
{% endhint %}

### Responses

#### `200` Success

#### Response Parameters

| Parameter              | Type    | Description                                                                                                                                                                                                                                                                                                                                                                                                                              |
| ---------------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `serviceResultCode`    | integer | Code indicating the **overall result** of the service execution. See [Service Result Code](#service-result-code)                                                                                                                                                                                                                                                                                                                         |
| `serviceResultLog`     | string  | Descriptive field for the result of the service execution. Details about the module are included in case of an error or exception.                                                                                                                                                                                                                                                                                                       |
| `serviceTime`          | string  | Total service execution time **(milliseconds)**.                                                                                                                                                                                                                                                                                                                                                                                         |
| `serviceDocument`      | string  | Object representing the captured document. Its properties are **all fields extracted by the OCR process**, including the facial image present in the document. See [serviceDocument fields](https://docs.facephi.com/docs.facephi-en/rest-api/identity-api/identity-api-reference/onboarding/ocr/extract-document-data-web/extract-document-data-web-campos.md), which also lists the possible values for `countryCode` and `DOC_MODEL`. |
| `serviceTransactionId` | string  | Transaction identifier associated with the request processed by the API.                                                                                                                                                                                                                                                                                                                                                                 |

#### Service Result Code

The `serviceResultCode` indicates the overall result of the service execution:

| serviceResultCode | Description                                                                       | HTTP Code |
| ----------------- | --------------------------------------------------------------------------------- | --------- |
| 0                 | The service execution was successful; the module processed the request correctly. | 200       |

#### Response example

```json
{
  "serviceResultCode": 0,
  "serviceResultLog": "Service request successfully processed",
  "serviceTime": "2237",
  "serviceDocument": "{\"ASK4BACK\":\"NO\",\"BACKSIDE\":{\"FIELD_DATA\":{\"BARCODES\":[{\"DATA\":\"\",\"TYPE\":\"\"}]},\"MRZ_DATA\":{\"BIRTH_DATE\":\"01/01/1980\",\"EXPEDITION_DATE\":\"01/01/2020\",\"EXPIRATION_DATE\":\"01/01/2030\",\"IDENTITY_NUMBER\":\"123\",\"ISSUING_COUNTRY\":\"XYZ\",\"NAME\":\"JOHN\",\"NATIONALITY\":\"XYZ\",\"PERSONAL_NUMBER\":\"12345678\",\"SERIAL_NUMBER\":\"000000001\",\"SURNAME\":\"DOE\"}},\"CHECKS\":{\"BIRTH_DATE_SIDE_MATCH\":true,\"EXPEDITION_DATE_SIDE_MATCH\":true,\"EXPIRATION_DATE_SIDE_MATCH\":true,\"NAME_SIDE_MATCH\":true,\"NATIONALITY_SIDE_MATCH\":true,\"SURNAME_SIDE_MATCH\":true},\"COUNTRY_CODE\":\"XYZ\",\"DECOMPOSED\":{\"FACE\":\"/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAIBAQEBAQIBAQECAgICAgQDAgICAgUEBAMEBgUGBgYFBgYGBwkIBgcJBwYGCAsICQoKCgoKBggLDAsKDAkKCgr/p3Vg7fMCvXH/66ujh6VJXhFfkzHE4rEYqV6kmz/9k=...\"},\"DOC_MODEL\":\"NEW\",\"FRONTSIDE\":{\"FIELD_DATA\":{\"BIRTH_DATE\":\"01/01/1980\",\"BIRTH_PLACE\":\"SOMEPLACE/XYZ\",\"DOCUMENT_NUMBER\":\"1.234.567-8\",\"EXPEDITION_DATE\":\"01/01/2020\",\"EXPIRATION_DATE\":\"01/01/2030\",\"NAME\":\"JOHN\",\"NATIONALITY\":\"XYZ\",\"SURNAME\":\"DOE\"}},\"SCORING\":{\"BACK_CONFIDENCE\":0.927620202303,\"BACK_SHA256\":\"0f8b53d5724a186cf19c882baa20eb92fa6e1708065987a32ecbf0141a86e6a5\",\"FIELDS_RETURNED\":27,\"FIELDS_TOTAL\":27,\"FRONT_CONFIDENCE\":0.97401304245,\"FRONT_SHA256\":\"a3dccd459f4674ec8440a11c7c65ab0e1ebaa5fd8357b55484574e71116bef2c\",\"OVERALL_RATING\":100.0}}"
  "serviceTransactionId": "123e4567-e89b-12d3-a456-426614174000"
}
```

#### `400` Bad Request

```json
{
  "status": 400,
  "title": "Bad Request",
  "detail": "Invalid request.",
  "type": "https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/400",
  "errors": []
}
```

#### `401` Unauthorized

```json
{
  "message": "Unauthorized"
}
```

#### `403` Forbidden

```json
{
  "Message": "User is not authorized to access this resource with an explicit deny"
}
```

#### `413` Payload Too Large

The request exceeds the maximum allowed size. The gateway rejects it **without processing it**: the response does not include `serviceResultCode` or `serviceTransactionId`. See [Request size limit](https://docs.facephi.com/pages/bc7bee9358079d52bafa44ad281828eb424e96fe#l%C3%ADmite-de-tama%C3%B1o-de-la-solicitud).

Request larger than 6 MB and up to 10 MB (`Content-Type: application/json`):

```json
{
  "message": "Request Too Long"
}
```

Request larger than 10 MB (10,485,760 bytes) (`Content-Type: text; charset=utf-8`, plain text, not JSON):

```
HTTP content length exceeded 10485760 bytes.
```

#### `502` Bad Gateway

```json
{
  "status": 502,
  "title": "Bad Gateway",
  "detail": "Server got an invalid response.",
  "type": "https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/502"
}
```

#### `504` Gateway Timeout

```json
{
  "message": "Endpoint request timed out"
}
```
