Generate a Facturae 3.2.2 Electronic Invoice XML (FACe / B2B)
Skill: Convert invoice data into the Facturae 3.2.2 XML
Region: Spain (España)
Category: E-invoicing — Facturae (FACe)
Does: Takes a Spanish invoice (seller, buyer, line items, taxes, totals) and produces the Facturae v3.2.2 XML business payload, the structured electronic invoice used for B2G submission to public administrations through the FACe general entry point and increasingly for B2B exchange.
Standard: Facturae v3.2.2 (Ministerio de Hacienda / Ministerio de Asuntos Económicos y Transformación Digital)
A valid Facturae file must be signed with an XAdES electronic signature (ds:Signature, enveloped, XAdES-EPES or higher policy) and must validate against the official Facturae 3.2.2 XSD before it can be uploaded to FACe. This skill produces the unsigned business payload only — the example below shows the invoice content; the signing step and any DIR3/FACe routing codes must be applied and verified separately.
When this applies
- A Spanish issuer (autónomo or company, with NIF/CIF) raises an invoice and must deliver it electronically in Facturae format.
- B2G: invoicing a Spanish public administration — submission goes through FACe (Punto General de Entrada de Facturas Electrónicas), which requires the buyer's DIR3 administrative centre codes (oficina contable, órgano gestor, unidad tramitadora).
- B2B: invoicing another business in Facturae format (e.g. under the obligations introduced by the Ley Crea y Crece). For pure B2B the
AdministrativeCentres block is omitted.
- Excluded / not covered here: the XAdES signature itself, batch validation services, and the TicketBAI / VeriFactu regimes (separate skills).
Input data required
| Input |
→ Facturae element |
| Schema version, modality (single/batch), issuer role |
FileHeader/SchemaVersion, Modality, InvoiceIssuerType |
| Batch id, invoice count, currency, batch totals |
FileHeader/Batch/* |
| Seller NIF/CIF, person type, residence |
SellerParty/TaxIdentification/* |
| Seller legal name and address |
SellerParty/LegalEntity/CorporateName, .../AddressInSpain/* |
| Buyer NIF/CIF, person type, residence |
BuyerParty/TaxIdentification/* |
| Buyer legal name and address |
BuyerParty/LegalEntity/CorporateName, .../AddressInSpain/* |
| Buyer DIR3 codes (B2G only) |
BuyerParty/.../AdministrativeCentres/AdministrativeCentre/{CentreCode, RoleTypeCode} |
| Invoice number, series, document type, class |
InvoiceHeader/{InvoiceNumber, InvoiceSeriesCode, InvoiceDocumentType, InvoiceClass} |
| Issue date, currency, language |
InvoiceIssueData/{IssueDate, InvoiceCurrencyCode, TaxCurrencyCode, LanguageName} |
| Per-line description, qty, unit, unit price |
Items/InvoiceLine/{ItemDescription, Quantity, UnitOfMeasure, UnitPriceWithoutTax, TotalCost, GrossAmount} |
| Tax type, rate, base, amount |
TaxesOutputs/Tax/{TaxTypeCode, TaxRate, TaxableBase/TotalAmount, TaxAmount/TotalAmount} |
| Invoice totals |
InvoiceTotals/* |
| Payment means and due date |
PaymentDetails/Installment/{InstallmentDueDate, InstallmentAmount, PaymentMeans} |
Missing required fields: if the issuer NIF, buyer NIF, an amount, a tax rate, or (for B2G) a DIR3 code is absent or ambiguous, stop and ask. Do not invent identifiers, rates, or routing codes.
Document structure
fe:Facturae
├── FileHeader
│ ├── SchemaVersion (3.2.2)
│ ├── Modality (I single | L batch)
│ ├── InvoiceIssuerType (EM emisor | RE receptor | TE tercero)
│ └── Batch
│ ├── BatchIdentifier (series+number of the first invoice)
│ ├── InvoicesCount
│ ├── TotalInvoicesAmount/TotalAmount
│ ├── TotalOutstandingAmount/TotalAmount
│ ├── TotalExecutableAmount/TotalAmount
│ └── InvoiceCurrencyCode (EUR)
├── Parties
│ ├── SellerParty
│ │ ├── TaxIdentification {PersonTypeCode, ResidenceTypeCode, TaxIdentificationNumber}
│ │ └── LegalEntity | Individual
│ │ └── CorporateName / (Name+FirstSurname), AddressInSpain {Address, PostCode, Town, Province, CountryCode}
│ └── BuyerParty
│ ├── TaxIdentification {PersonTypeCode, ResidenceTypeCode, TaxIdentificationNumber}
│ ├── (B2G) AdministrativeCentres
│ │ └── AdministrativeCentre {CentreCode (DIR3), RoleTypeCode 01/02/03, ...}
│ └── LegalEntity | Individual { ... }
└── Invoices
└── Invoice (one per invoice in the batch)
├── InvoiceHeader {InvoiceNumber, InvoiceSeriesCode, InvoiceDocumentType, InvoiceClass}
├── InvoiceIssueData {IssueDate, InvoiceCurrencyCode, TaxCurrencyCode, LanguageName}
├── TaxesOutputs
│ └── Tax {TaxTypeCode, TaxRate, TaxableBase/TotalAmount, TaxAmount/TotalAmount}
├── InvoiceTotals {TotalGrossAmount, TotalGrossAmountBeforeTaxes, TotalTaxOutputs,
│ TotalTaxesWithheld, InvoiceTotal, TotalOutstandingAmount, TotalExecutableAmount}
├── Items
│ └── InvoiceLine {ItemDescription, Quantity, UnitOfMeasure, UnitPriceWithoutTax,
│ TotalCost, GrossAmount, TaxesOutputs/Tax}
└── PaymentDetails/Installment {InstallmentDueDate, InstallmentAmount, PaymentMeans}
AdministrativeCentres is mandatory for B2G (FACe routing) and omitted for B2B. TaxCurrencyCode equals InvoiceCurrencyCode (EUR) for domestic invoices. The ds:Signature element is added at the end of the document by the XAdES signer and is not shown here.
Source → Facturae field map
| From the source |
→ Facturae element |
| "Factura nº" / invoice number |
InvoiceHeader/InvoiceNumber |
| Invoice series prefix |
InvoiceHeader/InvoiceSeriesCode |
| Document kind (complete invoice) |
InvoiceHeader/InvoiceDocumentType = FC |
| Invoice class (original) |
InvoiceHeader/InvoiceClass = OO |
| Invoice date |
InvoiceIssueData/IssueDate (YYYY-MM-DD) |
| Currency |
InvoiceIssueData/InvoiceCurrencyCode = EUR |
| Seller CIF/NIF |
SellerParty/TaxIdentification/TaxIdentificationNumber |
| Seller company name |
SellerParty/LegalEntity/CorporateName |
| Seller address / CP / town / province |
SellerParty/LegalEntity/AddressInSpain/{Address, PostCode, Town, Province} |
| Buyer CIF/NIF |
BuyerParty/TaxIdentification/TaxIdentificationNumber |
| Buyer name |
BuyerParty/LegalEntity/CorporateName |
| Buyer oficina contable (DIR3) |
AdministrativeCentre[RoleTypeCode=01]/CentreCode |
| Buyer órgano gestor (DIR3) |
AdministrativeCentre[RoleTypeCode=02]/CentreCode |
| Buyer unidad tramitadora (DIR3) |
AdministrativeCentre[RoleTypeCode=03]/CentreCode |
| Line description |
InvoiceLine/ItemDescription |
| Line quantity |
InvoiceLine/Quantity |
| Unit of measure |
InvoiceLine/UnitOfMeasure (01 = units) |
| Net unit price |
InvoiceLine/UnitPriceWithoutTax |
| Line net total |
InvoiceLine/TotalCost and InvoiceLine/GrossAmount |
| VAT type / rate / base / amount (per line) |
InvoiceLine/TaxesOutputs/Tax/* |
| VAT summary (whole invoice) |
Invoices/Invoice/TaxesOutputs/Tax/* |
| Net total |
InvoiceTotals/TotalGrossAmountBeforeTaxes |
| Output VAT total |
InvoiceTotals/TotalTaxOutputs |
| Withholding total (IRPF) |
InvoiceTotals/TotalTaxesWithheld |
| Invoice grand total |
InvoiceTotals/InvoiceTotal |
| Amount due |
InvoiceTotals/TotalOutstandingAmount, TotalExecutableAmount |
| Payment due date / method |
PaymentDetails/Installment/{InstallmentDueDate, PaymentMeans} |
Code tables
InvoiceDocumentType
| Code |
Meaning |
FC |
Factura completa (complete/ordinary invoice) |
FA |
Factura simplificada / abreviada (simplified invoice) |
AF |
Autofactura (self-billed invoice) |
InvoiceClass
| Code |
Meaning |
OO |
Original |
OR |
Original rectificativa (corrective original) |
OC |
Original recapitulativa (summary original) |
CO |
Copia del original |
CR |
Copia de la rectificativa |
CC |
Copia de la recapitulativa |
TaxTypeCode
| Code |
Meaning |
01 |
IVA (impuesto sobre el valor añadido) |
02 |
IPSI (Ceuta y Melilla) |
03 |
IGIC (Canarias) |
04 |
IRPF (retención / withholding) |
05 |
Otro |
PersonTypeCode
| Code |
Meaning |
F |
Persona física (individual) |
J |
Persona jurídica (legal entity) |
ResidenceTypeCode
| Code |
Meaning |
R |
Residente en España |
U |
Residente en otro Estado miembro de la UE |
E |
Extranjero (resto del mundo) |
PaymentMeans (selección)
| Code |
Meaning |
01 |
En efectivo (cash) |
02 |
Recibo domiciliado (direct debit) |
04 |
Transferencia (bank transfer) |
05 |
Reposición (giro postal) |
13 |
Cheque |
14 |
Cheque nominativo |
16 |
Tarjeta (card) |
UnitOfMeasure (selección)
| Code |
Meaning |
01 |
Unidades (units) |
02 |
Horas |
03 |
Kilogramos |
04 |
Litros |
Calculation rules
- Line net (
TotalCost = GrossAmount) = Quantity × UnitPriceWithoutTax, rounded to 2 decimals.
- Line VAT = line
TaxableBase/TotalAmount × (TaxRate ÷ 100), rounded to 2 decimals.
- Per-tax summary base = sum of line taxable bases sharing the same
TaxTypeCode + TaxRate; summary VAT = summary base × rate.
TotalGrossAmountBeforeTaxes = sum of all line GrossAmount (net of tax), rounded to 2 decimals.
TotalTaxOutputs = sum of all output TaxAmount/TotalAmount (IVA, IGIC, IPSI).
TotalTaxesWithheld = sum of all withholding amounts (IRPF, TaxTypeCode 04); 0.00 when none.
InvoiceTotal = TotalGrossAmountBeforeTaxes + TotalTaxOutputs − TotalTaxesWithheld, rounded to 2 decimals.
TotalOutstandingAmount and TotalExecutableAmount = InvoiceTotal minus any prior payments / withholdings already settled (here equal to InvoiceTotal).
- Batch totals (
TotalInvoicesAmount, TotalOutstandingAmount, TotalExecutableAmount under FileHeader/Batch) = sums across all invoices in the batch.
- All amounts in EUR with 2 decimals, period as the decimal separator, no thousands separator. Recompute every total from the lines; flag any mismatch with a printed total in the source.
Worked example (end-to-end)
A Spanish consultancy (NIF B12345678) invoices the Ayuntamiento de Ejemplo (NIF P1234567A) for two service lines, single invoice (Modality I), 21 % IVA, EUR, B2G with DIR3 routing codes.
Intermediate figures:
- Line 1: 10 × 50.00 = 500.00 net.
- Line 2: 4 × 125.00 = 500.00 net.
- Net total (
TotalGrossAmountBeforeTaxes) = 500.00 + 500.00 = 1000.00.
- IVA 21 % on 1000.00 = 210.00 (
TotalTaxOutputs).
- Withheld = 0.00.
InvoiceTotal = 1000.00 + 210.00 − 0.00 = 1210.00.
<?xml version="1.0" encoding="UTF-8"?>
<fe:Facturae xmlns:fe="http://www.facturae.gob.es/formato/Versiones/Facturaev3_2_2.xml"
xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<FileHeader>
<SchemaVersion>3.2.2</SchemaVersion>
<Modality>I</Modality>
<InvoiceIssuerType>EM</InvoiceIssuerType>
<Batch>
<BatchIdentifier>FRA2026-0042</BatchIdentifier>
<InvoicesCount>1</InvoicesCount>
<TotalInvoicesAmount>
<TotalAmount>1210.00</TotalAmount>
</TotalInvoicesAmount>
<TotalOutstandingAmount>
<TotalAmount>1210.00</TotalAmount>
</TotalOutstandingAmount>
<TotalExecutableAmount>
<TotalAmount>1210.00</TotalAmount>
</TotalExecutableAmount>
<InvoiceCurrencyCode>EUR</InvoiceCurrencyCode>
</Batch>
</FileHeader>
<Parties>
<SellerParty>
<TaxIdentification>
<PersonTypeCode>J</PersonTypeCode>
<ResidenceTypeCode>R</ResidenceTypeCode>
<TaxIdentificationNumber>B12345678</TaxIdentificationNumber>
</TaxIdentification>
<LegalEntity>
<CorporateName>Consultoría Ejemplo S.L.</CorporateName>
<AddressInSpain>
<Address>Calle Mayor 10, 2º B</Address>
<PostCode>28013</PostCode>
<Town>Madrid</Town>
<Province>Madrid</Province>
<CountryCode>ESP</CountryCode>
</AddressInSpain>
</LegalEntity>
</SellerParty>
<BuyerParty>
<TaxIdentification>
<PersonTypeCode>J</PersonTypeCode>
<ResidenceTypeCode>R</ResidenceTypeCode>
<TaxIdentificationNumber>P1234567A</TaxIdentificationNumber>
</TaxIdentification>
<AdministrativeCentres>
<AdministrativeCentre>
<CentreCode>L01280001</CentreCode>
<RoleTypeCode>01</RoleTypeCode>
<Name>Intervención General</Name>
<CentreDescription>Oficina contable</CentreDescription>
</AdministrativeCentre>
<AdministrativeCentre>
<CentreCode>L01280002</CentreCode>
<RoleTypeCode>02</RoleTypeCode>
<Name>Concejalía de Hacienda</Name>
<CentreDescription>Órgano gestor</CentreDescription>
</AdministrativeCentre>
<AdministrativeCentre>
<CentreCode>L01280003</CentreCode>
<RoleTypeCode>03</RoleTypeCode>
<Name>Servicio de Contratación</Name>
<CentreDescription>Unidad tramitadora</CentreDescription>
</AdministrativeCentre>
</AdministrativeCentres>
<LegalEntity>
<CorporateName>Ayuntamiento de Ejemplo</CorporateName>
<AddressInSpain>
<Address>Plaza de la Constitución 1</Address>
<PostCode>28080</PostCode>
<Town>Madrid</Town>
<Province>Madrid</Province>
<CountryCode>ESP</CountryCode>
</AddressInSpain>
</LegalEntity>
</BuyerParty>
</Parties>
<Invoices>
<Invoice>
<InvoiceHeader>
<InvoiceNumber>0042</InvoiceNumber>
<InvoiceSeriesCode>FRA2026</InvoiceSeriesCode>
<InvoiceDocumentType>FC</InvoiceDocumentType>
<InvoiceClass>OO</InvoiceClass>
</InvoiceHeader>
<InvoiceIssueData>
<IssueDate>2026-06-12</IssueDate>
<InvoiceCurrencyCode>EUR</InvoiceCurrencyCode>
<TaxCurrencyCode>EUR</TaxCurrencyCode>
<LanguageName>es</LanguageName>
</InvoiceIssueData>
<TaxesOutputs>
<Tax>
<TaxTypeCode>01</TaxTypeCode>
<TaxRate>21.00</TaxRate>
<TaxableBase>
<TotalAmount>1000.00</TotalAmount>
</TaxableBase>
<TaxAmount>
<TotalAmount>210.00</TotalAmount>
</TaxAmount>
</Tax>
</TaxesOutputs>
<InvoiceTotals>
<TotalGrossAmount>1000.00</TotalGrossAmount>
<TotalGrossAmountBeforeTaxes>1000.00</TotalGrossAmountBeforeTaxes>
<TotalTaxOutputs>210.00</TotalTaxOutputs>
<TotalTaxesWithheld>0.00</TotalTaxesWithheld>
<InvoiceTotal>1210.00</InvoiceTotal>
<TotalOutstandingAmount>1210.00</TotalOutstandingAmount>
<TotalExecutableAmount>1210.00</TotalExecutableAmount>
</InvoiceTotals>
<Items>
<InvoiceLine>
<ItemDescription>Consultoría técnica — jornadas de análisis</ItemDescription>
<Quantity>10</Quantity>
<UnitOfMeasure>01</UnitOfMeasure>
<UnitPriceWithoutTax>50.00</UnitPriceWithoutTax>
<TotalCost>500.00</TotalCost>
<GrossAmount>500.00</GrossAmount>
<TaxesOutputs>
<Tax>
<TaxTypeCode>01</TaxTypeCode>
<TaxRate>21.00</TaxRate>
<TaxableBase>
<TotalAmount>500.00</TotalAmount>
</TaxableBase>
<TaxAmount>
<TotalAmount>105.00</TotalAmount>
</TaxAmount>
</Tax>
</TaxesOutputs>
</InvoiceLine>
<InvoiceLine>
<ItemDescription>Redacción de informe & entrega final</ItemDescription>
<Quantity>4</Quantity>
<UnitOfMeasure>01</UnitOfMeasure>
<UnitPriceWithoutTax>125.00</UnitPriceWithoutTax>
<TotalCost>500.00</TotalCost>
<GrossAmount>500.00</GrossAmount>
<TaxesOutputs>
<Tax>
<TaxTypeCode>01</TaxTypeCode>
<TaxRate>21.00</TaxRate>
<TaxableBase>
<TotalAmount>500.00</TotalAmount>
</TaxableBase>
<TaxAmount>
<TotalAmount>105.00</TotalAmount>
</TaxAmount>
</Tax>
</TaxesOutputs>
</InvoiceLine>
</Items>
<PaymentDetails>
<Installment>
<InstallmentDueDate>2026-07-12</InstallmentDueDate>
<InstallmentAmount>1210.00</InstallmentAmount>
<PaymentMeans>04</PaymentMeans>
</Installment>
</PaymentDetails>
</Invoice>
</Invoices>
</fe:Facturae>
Normalisation transformations shown: 21% → TaxRate 21.00; 12/06/2026 → IssueDate 2026-06-12; "transferencia" → PaymentMeans 04; "unidades" → UnitOfMeasure 01; the literal ampersand in "informe & entrega" escaped as &. The signed file adds a single enveloped ds:Signature before </fe:Facturae>.
Validation checklist
Last updated: 2026-06-12 — verify the active Facturae schema version, FACe/DIR3 codes, and signature policy against the current specification before use.