> 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 visible fields 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 for sending open images from any platform. When using the SelphID Web Widget, the images generated by the Widget are obtained from an image array.

### Endpoint

```
POST /services/extractDocumentDataWeb
```

### Headers

| Name          | Type   | Required | Description                                                |
| ------------- | ------ | -------- | ---------------------------------------------------------- |
| **x-api-key** | string | **Yes**  | Access authorization API Key.                              |
| **family**    | string | No       | Value: **Onboarding**. Required with the tracking service. |

{% hint style="info" %}
All calls to the Endpoints for tracking with **Identity Platform** must contain the header `family`.
{% endhint %}

### Request body

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

#### Parameters

| Parameter              | Type    | Required | Description                                                                                                                                                                                                                                                                                                          |
| ---------------------- | ------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `tokenFrontDocument`   | string  | **Yes**  | Image encoded in **Base64** from the front side of the document, removing the MIME type header.                                                                                                                                                                                                                      |
| `tokenBackDocument`    | string  | No       | Image encoded in **Base64** from the back side of the document, removing the MIME type header.                                                                                                                                                                                                                       |
| `countryCode`          | string  | **Yes**  | Country code in format [**ISO 3166-1 alpha-3**](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3). If it is not present in the request body, the service will use the default country defined for the client in the API configuration. For passports, only `tokenFrontDocument` with `countryCode` set in **"PSP"**. |
| `decompose`            | boolean | No       | Indicates whether the image of the face present in the document and the signature crop should be obtained. (\*) Consult the Latam Support team for enabled countries.                                                                                                                                                |
| `tracking`             | object  | No       | Object representing the necessary tracking information.                                                                                                                                                                                                                                                              |
| `tracking.extraData`   | string  | No       | Token generated by the SDK Mobile/Web. Contains tokenized tracking information with the Platform.                                                                                                                                                                                                                    |
| `tracking.operationId` | string  | No       | Operation identifier generated by the SDK Mobile/Web.                                                                                                                                                                                                                                                                |

#### Request example

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

### Responses

#### `200` Success

#### Response parameters

| Parameter              | Type    | Description                                                                                                                                                             |
| ---------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `serviceResultCode`    | integer | Code that indicates the **overall result** of the service execution. See [Service Result Code](#service-result-code)                                                    |
| `serviceResultLog`     | string  | Descriptive field of the result of the service execution. Module details are included in case of error or exception.                                                    |
| `serviceTime`          | string  | Total service execution time **(milliseconds)**.                                                                                                                        |
| `serviceDocument`      | string  | Object representing the captured document. Its properties are **all the fields extracted by the OCR process**, including the image of the face present in the document. |
| `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"
}
```

#### `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"
}
```
