> 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/form-ocr.md).

# Form OCR

Service that extracts fields from non-identifying printed documents: invoices, receipts and generic PDFs.

It is an exclusively online service: `source` only accepts the value `FILE`, and has no header `operation-id` and its assets do not participate in the operation cycle. A printed document is identified by its issuer (`issuerCode`) and not by its country.

### Endpoint

```
POST /form/ocr
```

### Headers

| Name              | Type   | Required | Description                                                                                                                   |
| ----------------- | ------ | -------- | ----------------------------------------------------------------------------------------------------------------------------- |
| **Authorization** | string | **Yes**  | Consumer Token in Bearer format `Bearer <token>`. See [Authentication](/docs.facephi-en/rest-api/midapi-v2/autenticacion.md). |
| **consumer-id**   | string | **Yes**  | Consumer identifier.                                                                                                          |

### Request body

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

#### Parameters

| Parameter        | Type    | Required | Description                                                                                         |
| ---------------- | ------- | -------- | --------------------------------------------------------------------------------------------------- |
| `source`         | string  | **Yes**  | Only `FILE`. Any other value is rejected with `400`.                                                |
| `files`          | array   | **Yes**  | Pages of the printed document in order, in Base64. A printed document can have any number of pages. |
| `formType`       | string  | **Yes**  | Printed document type: `INVOICE` or `PDF`.                                                          |
| `issuerCode`     | string  | **Yes**  | Issuer code of the printed document, agreed with the issuer. It is not a country code.              |
| `retrieveImages` | boolean | No       | Returns the cropped images in the response. By default `false`.                                     |

#### Request example

```json
{
  "source": "FILE",
  "files": ["<base64 page 1>", "<base64 page 2>"],
  "formType": "INVOICE",
  "issuerCode": "TELMEX"
}
```

### Responses

#### `200` Success

#### Response parameters

| Parameter              | Type    | Description                                                                  |
| ---------------------- | ------- | ---------------------------------------------------------------------------- |
| `serviceResultCode`    | integer | Code indicating the overall result of the service execution. `0` is success. |
| `serviceResultLog`     | string  | Descriptive field for the result of the service execution.                   |
| `serviceTransactionId` | string  | Transaction identifier associated with the processed request.                |
| `serviceTime`          | string  | Total processing time **(milliseconds)**.                                    |
| `timestamp`            | string  | Moment when processing finished, in format **ISO 8601**.                     |
| `serviceResult`        | object  | OCR result with the fields extracted from the printed document.              |

{% hint style="warning" %}
`FORM_OCR` is its own provisioning, separate from `DOCUMENT_OCR`. A consumer that processes invoices needs this service to be enabled.
{% endhint %}

#### Other responses

| Code  | Description                                                                                                                                                                               |
| ----- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `400` | `source` different from `FILE`, `formType` unknown, or required field missing.                                                                                                            |
| `401` | Missing, invalid, or expired Token.                                                                                                                                                       |
| `403` | The consumer is not provisioned with the service `FORM_OCR`.                                                                                                                              |
| `429` | The consumer has exceeded its request rate limit. The response includes `Retry-After` with the wait seconds, and `X-RateLimit-Limit` and `X-RateLimit-Burst` with the current thresholds. |

The body of an error response has the form described in [MIDAPI v2](/docs.facephi-en/rest-api/midapi-v2.md#respuestas-de-error).
