> 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.md).

# Extract Document Data

This service returns all the data extracted from an identity 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.

### Integration

This service is used for implementations of the **SelphID Mobile Widget** by sending the **TokenOCR** property generated by the widget's native function.

### Endpoint

```
POST /services/extractDocumentData
```

### 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                                                                                                                                                             |
| ---------------------- | ------ | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `tokenOcr`             | string | **Yes**  | Token generated by the native or hybrid SelphID widget, **encrypted with AES256** and tokenized, sent in **Base64**. Contains the OCR result from the document capture. |
| `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
{
  "tokenOcr": "BAMBAQLNHJoWGPjfeuDIzDXdZuP...",
  "tracking": {
    "extraData": "BQABAQG2gBNjuHN4kLmPqYf7R...",
    "operationId": "123e4567-e89b-12d3-a456-426614174000"
  }
}
```

{% hint style="warning" %}
**Maximum request size: 6 MB.** The Base64 token (`tokenOcr`) and the remaining fields count toward this limit. 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. |
| `serviceDocument`      | string  | Object representing the captured document. Its properties are **all fields extracted by the OCR process**.                         |
| `serviceTime`          | string  | Total service execution time **(milliseconds)**.                                                                                   |
| `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": "19",
  "serviceDocument": "{\"Back/BARCODE/BarcodeData\":\"ABC123\",\"Back/BARCODE/BarcodeType\":\"Code39\",\"Back/BARCODE/DocumentData\":\"ABC123\",\"Back/INPUT/Issuer\":\"USA\",\"Back/MRZ/DateOfBirth\":\"01/01/1980\",\"Back/MRZ/DateOfExpiry\":\"01/01/2030\",\"Back/MRZ/DocumentCode\":\"P\",\"Back/MRZ/DocumentData\":\"123456789\",\"Back/MRZ/DocumentNumber\":\"987654321\",\"Back/MRZ/FirstName\":\"JOHN\",\"Back/MRZ/FullName\":\"JOHN DOE\",\"Back/MRZ/Issuer\":\"USA\",\"Back/MRZ/LastName\":\"DOE\",\"Back/MRZ/MrzText\":\"P<USA123456789987654321<<<<<<<<<<<<<\\n8001015<3001017USA<<<<<<<<<<<1\\nDOE<<JOHN<<<<<<<<<<<<<<<<<<<<<\",\"Back/MRZ/Nationality\":\"USA\",\"Back/MRZ/NfcKey\":\"123456789\",\"Back/MRZ/Opt2\":\"300101\",\"Back/MRZ/PrimaryID\":\"DOE\",\"Back/MRZ/SecondaryID\":\"JOHN\",\"Back/MRZ/Verified\":\"YES\",\"DateOfBirth\":\"01/01/1980\",\"DateOfExpiry\":\"01/01/2030\",\"DateOfIssue\":\"01/01/2020\",\"DocumentCaptured\":\"US/v2\",\"DocumentNumber\":\"987654321\",\"FirstName\":\"JOHN\",\"Front/INPUT/Issuer\":\"USA\",\"Front/ML/DateOfBirth\":\"01/01/1980\",\"Front/ML/DateOfExpiry\":\"01/01/2030\",\"Front/ML/DateOfIssue\":\"01/01/2020\",\"Front/ML/DocumentNumber\":\"987654321\",\"Front/ML/FirstName\":\"JOHN\",\"Front/ML/LastName\":\"DOE\",\"Front/ML/Nationality\":\"USA\",\"FullName\":\"JOHN DOE\",\"Issuer\":\"USA\",\"LastName\":\"DOE\",\"MatchingSidesScore\":\"1.000\",\"Nationality\":\"USA\",\"NfcKey\":\"123456789\"}",
  "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"
}
```
