> 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-identity forms: invoices, receipts, and generic PDFs.

This is an online-only service: `source` only accepts the value `FILE`, it does not carry the `operation-id` header, and its assets are not part of the operation lifecycle. A form is identified by its issuer (`issuerCode`), not by its country.

### Endpoint

```
POST /form/ocr
```

### Headers

| Name              | Type   | Required | Description                                                                                                                             |
| ----------------- | ------ | -------- | --------------------------------------------------------------------------------------------------------------------------------------- |
| **Authorization** | string | **Yes**  | Consumer Token in `Bearer <token>`. See [Authentication](https://docs.facephi.com/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 form in order, in Base64. A form can have any number of pages. |
| `formType`       | string  | **Yes**  | Form type: `INVOICE` or `PDF`.                                              |
| `issuerCode`     | string  | **Yes**  | Form issuer code, agreed with the issuer. It is not a country code.         |
| `retrieveImages` | boolean | No       | Returns the cropped images in the response. Default is `false`.             |

#### Request example

```json
{
  "source": "FILE",
  "files": ["<base64 página 1>", "<base64 página 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` indicates 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  | Time when processing finished, in **ISO 8601**.                                     |
| `serviceResult`        | object  | OCR result with the fields extracted from the form.                                 |

{% hint style="warning" %}
`FORM_OCR` is provisioned separately from `DOCUMENT_OCR`. A consumer that processes invoices needs this service to be enabled for it.
{% endhint %}

#### Other responses

| Code  | Description                                                                                                                                                                                            |
| ----- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `400` | `source` other than `FILE`, `formType` unknown, or a required field is missing.                                                                                                                        |
| `401` | Token missing, invalid, or expired.                                                                                                                                                                    |
| `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 number of seconds to wait, and `X-RateLimit-Limit` and `X-RateLimit-Burst` with the current thresholds. |

The body of an error response has the format described in [API v2 Middleware](https://docs.facephi.com/docs.facephi-en/rest-api/midapi-v2.md#respuestas-de-error).
