> For the complete documentation index, see [llms.txt](https://api.qvalia.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://api.qvalia.io/api-documentation/apis/enrichment-api/pdf-capture.md). Agents can also search and read this documentation through its [MCP server](https://api.qvalia.io/~gitbook/mcp).

# PDF capture

Extract invoice data from a PDF and get it back as a Peppol BIS Billing 3.0 invoice.

The invoice endpoint reads a PDF invoice and returns the extracted data as a Peppol BIS Billing 3.0 (UBL) invoice. You can then process it the same way as an e-invoice.

{% hint style="info" %}
PDF capture is part of the Enrichment API, which is billed separately. Contact [Qvalia Helpdesk](https://qvalia.com/help/) to enable `capture` for your account.
{% endhint %}

## How it works

Capture is asynchronous:

{% stepper %}
{% step %}

### Upload the PDF

`POST /enrichment/{accountRegNo}/invoice` with the Base64-encoded PDF. The response is `202 Accepted` with a `pollingId` and a `Location` header.
{% endstep %}

{% step %}

### Poll for the result

`GET /enrichment/{accountRegNo}/{pollingId}` returns `202` while processing and `200` when the result is ready. Every poll counts toward your account's [rate limit](https://api.qvalia.io/qvalia-developer-tools/api.md#rate-limit), so pace your polling with the `RateLimit-Remaining` and `RateLimit-Reset` response headers.
{% endstep %}

{% step %}

### Read the invoice

The extracted invoice is under `data.capture.result.Invoice`, with any extraction problems listed in `errors` and `warnings`.
{% endstep %}
{% endstepper %}

## Upload a PDF

```http
POST /enrichment/{accountRegNo}/invoice
Authorization: <api key>
Content-Type: application/json
```

```json
{
  "enrichmentTypes": "capture",
  "fileName": "invoice-12345.pdf",
  "fileContent": "JVBERi0xLjcKJeLjz9MKMSAwIG9iago8PC9UeXBlL0NhdGFsb2c..."
}
```

Response:

```json
{
  "status": "success",
  "data": { "pollingId": "6a8c46b0-aed1-49cd-8010-aa7c84db870e" }
}
```

### Request fields

| Field             | Type   | Required | Notes                                                                                  |
| ----------------- | ------ | -------- | -------------------------------------------------------------------------------------- |
| `enrichmentTypes` | string | Yes      | Must be `capture`. Can also be sent as the query parameter `?enrichmentTypes=capture`. |
| `fileContent`     | string | Yes      | The PDF file, Base64 encoded. One invoice per file.                                    |
| `fileName`        | string | No       | File name including extension, e.g. `invoice-12345.pdf`. Defaults to `invoice.pdf`.    |

Only PDF files are accepted. A file that is not a PDF returns `400 Bad Request` with `metadata.details: "file is not a valid PDF"`.

## Poll for the result

```http
GET /enrichment/{accountRegNo}/{pollingId}
```

While processing, the response is `202`:

```json
{ "status": "pending", "data": {} }
```

When complete, the response is `200`. The invoice is returned as UBL converted to JSON: every element is an array, the text value is in `_`, and attributes are in `$`.

```json
{
  "status": "success",
  "data": {
    "capture": {
      "result": {
        "Invoice": {
          "cbc:CustomizationID": [{ "_": "urn:cen.eu:en16931:2017#compliant#urn:fdc:peppol.eu:2017:poacc:billing:3.0" }],
          "cbc:ID": [{ "_": "12345" }],
          "cbc:IssueDate": [{ "_": "2024-07-01" }],
          "cbc:InvoiceTypeCode": [{ "_": 380 }],
          "cbc:DocumentCurrencyCode": [{ "_": "SEK" }],
          "cac:AccountingSupplierParty": [
            {
              "cac:Party": [
                {
                  "cbc:EndpointID": [{ "_": "556591-8868", "$": { "schemeID": "0088" } }],
                  "cac:PartyName": [{ "cbc:Name": [{ "_": "STC Johanneshov Hammarbyhöjden" }] }]
                }
              ]
            }
          ]
        }
      },
      "errors": [],
      "warnings": []
    }
  }
}
```

{% hint style="success" %}
Send `Accept: application/xml` when polling to get the invoice as Peppol BIS Billing 3.0 UBL XML instead of JSON.
{% endhint %}

You can also get only the capture result with `GET /enrichment/{accountRegNo}/{pollingId}/capture`. It returns the same `result`, `errors` and `warnings` directly under `data`.

### Result fields

| Field            | Type   | Notes                                                                                                                          |
| ---------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------ |
| `result.Invoice` | object | The extracted invoice as Peppol BIS Billing 3.0 UBL.                                                                           |
| `errors`         | array  | Messages for main attributes that could not be extracted correctly. Check them against your use case before using the invoice. |
| `warnings`       | array  | Non-critical problems found during extraction.                                                                                 |

## Limits and errors

| Situation                                                                                                                                                                    | Response                                                                      |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- |
| `fileContent` missing, not a PDF, or an invalid `enrichmentTypes`                                                                                                            | `400` with `type: E_BAD_REQUEST`; `metadata.details` describes the problem.   |
| `capture` not enabled for the account                                                                                                                                        | `401` with `data: "Unauthorized for service capture"`.                        |
| Over the account's [rate limit](https://api.qvalia.io/qvalia-developer-tools/api.md#rate-limit) (200 requests a minute by default, 800 for partners). Polls count toward it. | `429` — wait for `Retry-After` seconds (the time left in the current minute). |
| Unknown polling ID                                                                                                                                                           | `404` with `type: E_MISSING`.                                                 |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://api.qvalia.io/api-documentation/apis/enrichment-api/pdf-capture.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
