Automation MCP Server Blog Pricing
Automation

ZUGFeRD in Servoy: E-Invoices from Your Servoy Application with One API

Servoy applications already print invoices, usually with JasperReports. German law now asks for e-invoices with structured XML. This guide adds ZUGFeRD to a Servoy solution with one JavaScript function and the http plugin. Your invoice layout stays as it is. XRechnung for public buyers uses the same invoice data.

This guide adds ZUGFeRD e-invoices to a Servoy application. Servoy is a low-code platform for business software: a solution scripted in JavaScript, running on the Servoy Application Server against your own database. Most Servoy applications already print a PDF invoice, often with JasperReports. A ZUGFeRD invoice is that PDF with the invoice data embedded as XML. With the InvoiceXML API this takes one JavaScript function and the http plugin that ships with Servoy.


Why Servoy applications need ZUGFeRD

German businesses must send e-invoices. Every German business has had to accept structured e-invoices since January 2025. Businesses with more than EUR 800,000 turnover in the previous year must issue them from January 2027. All other businesses follow in January 2028. A PDF from JasperReports is a plain PDF and does not count. The mandate map lists the dates by country.

One change for every customer. Many Servoy applications are vertical products sold to many companies. Build ZUGFeRD into the product once, and every customer can send e-invoices after the next update.

Format updates stay out of your solution. ZUGFeRD, XRechnung and the EN 16931 rules get new versions. The API applies each version from its start date. Your function sends the same JSON before and after, so no new release of your application is needed for a format change.


What you need

  • A Servoy solution with an invoice table and an invoice line table, in any database Servoy supports.
  • Your invoice as a PDF, for example from your JasperReports invoice report. If you have none, see one call without your own PDF.
  • HTTPS access from the Servoy Application Server to api.invoicexml.com.
  • An InvoiceXML API key. Start a free trial, no credit card needed. Keep the key in a settings table or in your server configuration, not in the solution source.

How it works

The function makes two calls. The first turns your invoice data into the e-invoice XML. The second puts that XML into your PDF.

CallEndpointYou sendYou get
1. Create the XMLPOST /v1/create/ciiInvoice data as JSONInvoice XML (EN 16931)
2. Embed it in your PDFPOST /v1/embed/zugferdYour PDF and the XMLZUGFeRD invoice as PDF/A-3

The API checks the invoice against the ZUGFeRD and EN 16931 rules before it returns the file. If something is missing, such as the seller VAT id or the IBAN, it answers with status 400 and a list of the problems. Your solution never stores an invalid e-invoice.


Step 1: Map your invoice to JSON

The API takes the invoice as JSON. Build it from your invoice record, its lines and your company data. Send only the base values. The API calculates line totals, VAT and invoice totals from the lines.

Your dataJSON pathExample
Invoice numberinvoiceNumberRE-2026-1001
Invoice date, due dateissueDate, dueDate2026-11-30
CurrencycurrencyEUR
Your company: name, VAT id, addressseller.name, seller.vatIdentifier, seller.postalAddressDE123456789
Customer: name, VAT id, addressbuyer.name, buyer.vatIdentifier, buyer.postalAddressDE987654321
Your IBANpaymentDetails.paymentAccountIdentifierDE89370400440532013000
Line quantity and unitlines[].quantity, lines[].unitCode2, H87 (piece) or HUR (hour)
Article namelines[].item.nameBeratung
Net unit pricelines[].priceDetails.netPrice150.00
VAT ratelines[].vatInformation.rate19

A complete invoice object looks like this:

var invoice = {
    invoiceNumber: 'RE-2026-1001',
    issueDate: '2026-11-30',
    dueDate: '2026-12-14',
    currency: 'EUR',
    seller: {
        name: 'Ihre Firma GmbH',
        vatIdentifier: 'DE123456789',
        postalAddress: { line1: 'Hauptstraße 1', city: 'Berlin', postCode: '10115', country: 'DE' }
    },
    buyer: {
        name: 'Kunde AG',
        vatIdentifier: 'DE987654321',
        postalAddress: { line1: 'Marktplatz 5', city: 'Köln', postCode: '50667', country: 'DE' }
    },
    paymentDetails: { paymentAccountIdentifier: 'DE89370400440532013000' },
    lines: [{
        quantity: 2,
        unitCode: 'H87',               // H87 = piece, HUR = hour
        item: { name: 'Beratung' },
        priceDetails: { netPrice: 150.00 },
        vatInformation: { rate: 19 }
    }]
};

In your solution, fill these values from the invoice record and loop over its line foundset to build lines. The full list of fields, such as order references, discounts and delivery dates, is in the create endpoint reference.


Step 2: Add the ZUGFeRD function

Add this function to a scope or a module in your solution. It takes the invoice object and the PDF bytes and returns the ZUGFeRD invoice. It uses only the http plugin and the file plugin.

var API = 'https://api.invoicexml.com';
var API_KEY = 'YOUR_API_KEY';   // load it from your settings table

/**
 * Turns the invoice data and your PDF into a ZUGFeRD invoice.
 * @param {Object} invoice the invoice data (see step 1)
 * @param {byte[]} pdfBytes your invoice PDF, for example from JasperReports
 * @return {byte[]} the ZUGFeRD invoice as PDF/A-3
 */
function createZugferd(invoice, pdfBytes) {
    var client = plugins.http.createNewHttpClient();

    // 1. Send the invoice data as JSON, get the invoice XML back
    var create = client.createPostRequest(API + '/v1/create/cii');
    create.addHeader('Authorization', 'Bearer ' + API_KEY);
    create.setBodyContent(JSON.stringify({ invoice: invoice }), 'application/json');
    var xmlResponse = create.executeRequest();
    if (xmlResponse.getStatusCode() != 200) {
        throw new Error('create/cii ' + xmlResponse.getStatusCode() + ': ' + xmlResponse.getResponseBody());
    }

    // 2. Upload the PDF and the XML, get the ZUGFeRD PDF back
    var pdfFile = plugins.file.createTempFile('invoice', '.pdf');
    plugins.file.writeFile(pdfFile, pdfBytes);
    var xmlFile = plugins.file.createTempFile('invoice', '.xml');
    plugins.file.writeTXTFile(xmlFile, xmlResponse.getResponseBody(), 'UTF-8');

    var embed = client.createPostRequest(API + '/v1/embed/zugferd');
    embed.addHeader('Authorization', 'Bearer ' + API_KEY);
    embed.addFile('pdf', 'invoice.pdf', pdfFile);
    embed.addFile('xml', 'invoice.xml', xmlFile);
    var pdfResponse = embed.executeRequest();
    if (pdfResponse.getStatusCode() != 200) {
        throw new Error('embed/zugferd ' + pdfResponse.getStatusCode() + ': ' + pdfResponse.getResponseBody());
    }
    return pdfResponse.getMediaData();
}

The embed endpoint takes a multipart form with two files: pdf and xml. The http plugin builds that form with addFile, so the function writes both to temporary files first. On an error, the response body is JSON with the rule and the field that failed. Show it to the user or write it to your log.


Step 3: Call it for each invoice

Call the function where your solution finalizes an invoice, for example in the method behind the "Print invoice" button. Keep the result next to the invoice, in a media column or in your document archive:

var pdfBytes = renderInvoicePdf(record);       // your JasperReports invoice as PDF bytes
var invoice = buildInvoiceJson(record);        // the mapping from step 1

record.zugferd_pdf = createZugferd(invoice, pdfBytes);   // a media column
databaseManager.saveData(record);

Then send the stored file to the customer the way you send invoices today, for example as an email attachment. To create e-invoices for many invoices at once, run the same code in a batch processor on the Servoy Application Server.


XRechnung for German public buyers

Public buyers in Germany ask for XRechnung instead of ZUGFeRD. XRechnung is XML only, so no PDF is needed. Post the same invoice object to /v1/create/xrechnung, with four additions:

invoice.buyerReference = '04011000-12345-34';   // the Leitweg-ID of the public buyer
invoice.seller.contact = { name: 'Buchhaltung', phone: '+49 30 123456', email: '[email protected]' };
invoice.seller.electronicAddress = { identifier: 'DE123456789', schemeId: '9930' };   // 9930 = German VAT id
invoice.buyer.electronicAddress = { identifier: '04011000-12345-34', schemeId: '0204' };  // 0204 = Leitweg-ID

The call is step 1 of the function with the other path. The response body is the XRechnung XML. Store it, then upload it to the invoice portal of the public buyer or send it by email. Keep the Leitweg-ID in your customer table, so the solution can choose XRechnung for these customers on its own.


One call without your own PDF

If your solution has no PDF invoice, let the API build it. Post the same JSON to /v1/create/zugferd. The API creates the XML, renders a PDF invoice from the data, embeds the XML and returns the ZUGFeRD PDF in one call. Read the response with getMediaData(), as in step 2.


Endpoint reference

PurposeEndpointInputOutput
Create the invoice XMLPOST /v1/create/ciiInvoice JSONCII XML
Embed the XML in your PDFPOST /v1/embed/zugferdPDF and XML fileZUGFeRD PDF/A-3
Create ZUGFeRD with a rendered PDFPOST /v1/create/zugferdInvoice JSONZUGFeRD PDF/A-3
Create XRechnungPOST /v1/create/xrechnungInvoice JSON with Leitweg-IDXRechnung XML

Get started

ZUGFeRD in Servoy is one function: map the invoice, send it, embed it in your PDF. The function holds no format logic, so new ZUGFeRD and XRechnung versions need no change in your solution. This guide is part of the integrations hub, which covers SAP, Microsoft Dynamics, Odoo and more platforms.

Related guides:

Start free today

Ready to automate your invoices?

Validate, convert and embed compliant e-invoices through one API. Start your 30-day free trial. No credit card required.

GDPR Compliant No credit card required Setup in minutes
Peppol UBL
Factur-X
EN 16931
142 / 142 passed
Compliant
PDF/A-3 embedded