Overview
The API can extract the invoice data from a PDF file and convert it to a UBL document. Use this method when:- You have PDF invoices that you want to send through Peppol.
- Your system generates PDF invoices but no structured data.
- You migrate from PDF invoicing to e-invoicing.
How it works
A PDF upload does not create a document in your company. The API returns the extracted invoice data as JSON, with these fields in addition to the invoice fields:
After the upload, you do these steps:
- Examine the extracted data. The extraction can contain errors.
- Create the document: from the
ubl_documentwithPOST /api/documents/ubl, or from the corrected JSON withPOST /api/documents/. - Send the document.
All upload requests use
multipart/form-data with one form field with the name file.
Synchronous upload
POST /api/documents/pdf has two optional query parameters.
string
Tax ID of the vendor. If you do not give it, the API uses the tax ID of your company.
string
Tax ID of the customer. The API uses it as input for the extraction.
BE1018265814) as vendor and OpenPeppol VZW (BE0848934496) as customer. Replace the vendor tax ID with that of your company.
201, shortened). This block is a response and not a request body. The UBL string is shortened, so do not use the block as input.
The response has no
id, because the upload does not store a document. The values state and direction are the values that the document gets when you create it.success: false, error_type: "ExtractionError" and one placeholder line with the description Line items could not be extracted from PDF.
Create and send the document
If the response has aubl_document, save the string to a file and create the document from it. POST /api/documents/ubl accepts multipart/form-data with a file field, not a raw XML body.
cURL
DRAFT, with an id such as doc-1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d. For this request in five languages and for the response, see Send UBL documents.
If the response has no ubl_document, or if the extracted data is not correct, correct the JSON and create the document with POST /api/documents/. See Create e-invoices.
Then send the document. The samples read the document ID from the environment variable DOCUMENT_ID.
200, shortened):
Asynchronous upload
The asynchronous upload has no tax ID parameters. The API uses the tax ID of your company as the vendor tax ID.1
Start the conversion
cURL
201):2
Poll the status
cURL
404 with the detail PDF conversion task not found or expired. Continue to poll. When the task is complete, the response is 200:status is completed or failed.3
Get the result
cURL
200) has the same structure as the response of the synchronous upload. For a failed task, success is false and error_message and error_type give the cause.Upload and poll (Node.js and Python)
Upload and poll (Node.js and Python)
Complete example
The example uploads a PDF, creates the document from the generated UBL and sends it. It needs only the environment variableE_INVOICE_API_KEY. In a production integration, examine the extracted data before the send step.
From PDF to sent document (Node.js and Python)
From PDF to sent document (Node.js and Python)
PDF requirements
- The file must be a PDF that is not empty and not damaged.
- A text-based PDF (generated by software) gives better results than a scanned document.
- Put one invoice in each PDF.
- Use a clear layout with separate sections for the vendor, the customer and the line items.
- All mandatory invoice fields must be visible in the PDF.
The API does not publish a size limit for these two upload endpoints. Keep the files small, and use the asynchronous upload if your client or proxy has a short timeout.
Troubleshooting
For all status codes and error formats, see Errors and troubleshooting.
Best practices
- Give
vendor_tax_idandcustomer_tax_idwith the synchronous upload. - Check
successandubl_documentbefore you continue. If one of them is missing, a person must examine the data. - Examine the important fields (
invoice_id,invoice_total, the tax IDs and the line items) before you send. - Use the asynchronous upload when you convert many PDF files, and limit the number of conversions that run at the same time.
- Keep the original PDF files for your audit records.
- Develop and test with a sandbox company. See Test mode and sandbox companies.
Next Steps
Send UBL documents
Create and send a document from UBL XML
Attachments and PDF
Add a PDF or other files to a JSON document
Send invoices by email (Mailbox)
Let your ERP email invoices to e-invoice.be
Errors and troubleshooting
Status codes, error formats and retry rules