Mapping JSON Invoice Fields to KSeF FA(3) XML

Invoice Field Mapping Guide (B2Brouter API ↔ Business Terms ↔ KSeF FA(3) XPath)

This guide details the mapping between the B2Brouter Invoice API fields, the corresponding Business Terms (BT) as defined by the European e-Invoicing standard (EN 16931), and the XML paths in the KSeF FA(3) format (Polish National e-Invoice System).

Its purpose is to help understand how invoice data submitted in JSON format via the Invoice API corresponds to the KSeF FA(3) XML structure. Only fields that are actually mapped during tax report generation are included.

Note: KSeF uses a Poland-specific XML schema (FA variant 3, schema version 1-0E) which differs significantly from EN 16931 formats like UBL or CII. Not all EN 16931 Business Terms have a direct equivalent in KSeF, and KSeF introduces Poland-specific fields not present in the European standard.

Note: The seller/supplier information (Podmiot1) is automatically populated from your account settings. The buyer/customer information (Podmiot2) is populated from the invoice contact. If you need direct control over all fields, consider using the Tax Report API instead.


Header-Level Mapping

BT IDBusiness TermAPI Field (B2Brouter)KSeF FA(3) XPath
BT-1Invoice Numberinvoice.numberFa/P_2
BT-2Invoice Issue Dateinvoice.dateFa/P_1
BT-3Invoice Type Codeinvoice.type_document Derived: defaults to VAT; KOR if amended invoice; ZAL if advance; UPR if simplifiedFa/RodzajFaktury
BT-5Invoice Currencyinvoice.currencyFa/KodWaluty
BT-7Tax Point Dateinvoice.tax_point_dateFa/P_6
BT-9Payment Due Dateinvoice.due_dateFa/Platnosc/TerminPlatnosci/Termin
BT-25Preceding Invoice Numberinvoice.amended_numberFa/DaneFaKorygowanej/NrFaKorygowanej
BT-26Preceding Invoice Issue Dateinvoice.amended_dateFa/DaneFaKorygowanej/DataWystFaKorygowanej
Exchange Rateinvoice.exchange_rateFa/KursWalutyZ
BT-13Purchase Order Referenceinvoice.ponumberFa/WarunkiTransakcji/Zamowienia/NrZamowienia
BT-14Sales Order Referenceinvoice.sales_order_referenceFa/DodatkowyOpis (key-value pair)
Correction Effect Codeinvoice.amend_code_tax or tax_report_setting.credit_note_codeFa/TypKorekty (only for KOR types)

Payment-Level Mapping

BT IDBusiness TermAPI Field (B2Brouter)KSeF FA(3) XPath
BT-9Payment Due Dateinvoice.due_dateFa/Platnosc/TerminPlatnosci/Termin
BT-81Payment Means Codeinvoice.payment_method (mapped to KSeF codes)Fa/Platnosc/FormaPlatnosci
BT-84Payee Financial Account IBANinvoice.bank_account.ibanFa/Platnosc/RachunekBankowy/NrRB
BT-84-0Payee Financial Account Numberinvoice.bank_account.number (fallback if no IBAN)Fa/Platnosc/RachunekBankowy/NrRB
BT-85Payee Financial Account Nameinvoice.bank_account.nameFa/Platnosc/RachunekBankowy/NazwaBanku
BT-86Payee Financial Account BICinvoice.bank_account.bicFa/Platnosc/RachunekBankowy/SWIFT
Paid FlagDerived: 1 when payable_amount = 0 and total > 0Fa/Platnosc/Zaplacono
Payment Date (when paid)invoice.due_date (when Zaplacono=1)Fa/Platnosc/DataZaplaty

Note: KSeF does not support card account details (BT-87, BT-88), direct debit mandates (BT-89), creditor references (BT-90), payment terms text (BT-20), or remittance information (BT-83).

Parties Mapping

This mapping is described for an issued invoice. If you want to map a received invoice, swap Podmiot1 and Podmiot2.

Podmiot1 (Seller/Supplier)

The Podmiot1 is automatically populated based on your account settings. This includes company name, NIP (Polish tax ID), and address.

BT IDBusiness TermAPI Field (B2Brouter)KSeF FA(3) XPath
Seller Country Prefixaccount.country (uppercased)Podmiot1/PrefiksPodatnika
BT-31Seller Tax Registration ID (NIP)account.tin_value (without country prefix)Podmiot1/DaneIdentyfikacyjne/NIP
BT-27Seller Party Nameaccount.namePodmiot1/DaneIdentyfikacyjne/Nazwa
BT-40Seller Address Countryaccount.country (uppercased)Podmiot1/Adres/KodKraju
BT-35Seller Address Streetaccount.addressPodmiot1/Adres/AdresL1
BT-37,38Seller Postal Code + Cityaccount.postalcode + account.cityPodmiot1/Adres/AdresL2
BT-29-0Seller GLNaccount.cin_value (if cin_scheme = 88)Podmiot1/Adres/GLN

Podmiot2 (Buyer/Customer)

BT IDBusiness TermAPI Field (B2Brouter)KSeF FA(3) XPath
BT-48Buyer Tax Registration IDinvoice.contact.tin_valuePL: Podmiot2/DaneIdentyfikacyjne/NIP
EU: Podmiot2/DaneIdentyfikacyjne/NrVatUE
Non-EU: Podmiot2/DaneIdentyfikacyjne/NrID
Buyer Tax Country (EU)invoice.contact.country (uppercased)Podmiot2/DaneIdentyfikacyjne/KodUE (EU only)
Buyer Tax Country (Non-EU)invoice.contact.country (uppercased)Podmiot2/DaneIdentyfikacyjne/KodKraju (non-EU only)
No Tax ID FlagDerived: 1 when contact.tin_value is blankPodmiot2/DaneIdentyfikacyjne/BrakID
BT-44Buyer Party Nameinvoice.contact.namePodmiot2/DaneIdentyfikacyjne/Nazwa
BT-55Buyer Address Countryinvoice.contact.country (uppercased)Podmiot2/Adres/KodKraju
BT-50Buyer Address Streetinvoice.contact.addressPodmiot2/Adres/AdresL1
BT-52,53Buyer Postal Code + Cityinvoice.contact.postalcode + invoice.contact.cityPodmiot2/Adres/AdresL2
BT-46-0Buyer GLNinvoice.contact.cin_value (if cin_scheme = 88)Podmiot2/Adres/GLN

Delivery Mapping (Podmiot3) as Role '2'

Delivery information is mapped to Podmiot3 (third party) with role code 2 (recipient) when invoice.delivery_address is present. The delivery address is also duplicated under Fa/WarunkiTransakcji/Transport/WysylkaDo.

BT IDBusiness TermAPI Field (B2Brouter)KSeF FA(3) XPath
BT-70Delivery Party Nameinvoice.delivery_party_namePodmiot3/DaneIdentyfikacyjne/Nazwa
BT-71Delivery Location ID (GLN)invoice.delivery_location_id (if type is GLN/088)Podmiot3/Adres/GLN
BT-75Delivery Address Streetinvoice.delivery_addressPodmiot3/Adres/AdresL1 and Fa/WarunkiTransakcji/Transport/WysylkaDo/AdresL1
BT-77,78Delivery Postal Code + Cityinvoice.delivery_postalcode + invoice.delivery_cityPodmiot3/Adres/AdresL2 and Fa/WarunkiTransakcji/Transport/WysylkaDo/AdresL2
BT-80Delivery Countryinvoice.delivery_countryPodmiot3/Adres/KodKraju and Fa/WarunkiTransakcji/Transport/WysylkaDo/KodKraju
Third Party RoleFixed: 2 (Recipient)Podmiot3/Rola

Note: KSeF does not support delivery date (BT-72) or delivery period fields.

Order & Transaction References (WarunkiTransakcji / DodatkowyOpis)

The WarunkiTransakcji section is rendered when a delivery address is present (third party role = 2) or when a purchase order reference is provided. The sales order reference is rendered as a DodatkowyOpis key-value pair.

Note: When a delivery address is present, KSeF also includes transport details (Transport/TransportInny, OpisInnegoTransportu, etc.) with default values (wg ustalenia/umowy) inside WarunkiTransakcji.

Invoice Line-Level Mapping (FaWiersz)

All attributes listed in the following table are properties of objects contained in the array: invoice.invoice_lines_attributes[]. The API Field column refers to keys within each invoice line object.

For regular invoices (VAT, KOR, UPR, ROZ), lines are rendered as FaWiersz elements. For advance payment invoices (ZAL, KOR_ZAL), lines are rendered as ZamowienieWiersz elements.

BT IDBusiness TermAPI Field (invoice line object)KSeF FA(3) XPath
BT-126Invoice Line IDpositionFa/FaWiersz/NrWierszaFa
BT-153Item NamedescriptionFa/FaWiersz/P_7
BT-130Billed Quantity (Unit Code)unit (check API Reference for code list)Fa/FaWiersz/P_8A
BT-129Billed QuantityquantityFa/FaWiersz/P_8B
BT-155Item Seller Identifierarticle_codeFa/FaWiersz/Indeks
BT-157Item Standard Identifier (GTIN)article_code2Fa/FaWiersz/GTIN
BT-146Price AmountpriceFa/FaWiersz/P_9A
-Discount Unit PriceDerived from discount_amount / quantityFa/FaWiersz/P_10
BT-131Line Net Amountextension_amount (if not provided, it will be calculated)Fa/FaWiersz/P_11
Line Tax AmountComputed from taxesFa/FaWiersz/P_11Vat
Tax CodeDerived from tax characteristicsFa/FaWiersz/P_12

Additional Item Properties Mapping (DodatkowyOpis per Line)

Each invoice line can carry additional key-value properties that map to line-level DodatkowyOpis elements in the KSeF XML. These correspond to EN 16931 Business Terms BT-160 (Item Attribute Name) and BT-161 (Item Attribute Value).

All attributes listed in the following table are properties of objects contained in the array: invoice.invoice_lines_attributes[].additional_item_properties_attributes[].

BT IDBusiness TermAPI Field (additional item property object)KSeF FA(3) XPath
Line Number ReferenceParent line's positionFa/DodatkowyOpis/NrWiersza
BT-160Item Attribute Namename (max 255 chars)Fa/DodatkowyOpis/Klucz
BT-161Item Attribute Valuevalue (max 255 chars)Fa/DodatkowyOpis/Wartosc

Example JSON:

{
  "invoice": {
    "invoice_lines_attributes": [
      {
        "position": 1,
        "description": "Product A",
        "additional_item_properties_attributes": [
          { "name": "Color", "value": "Red" },
          { "name": "Size", "value": "XL" }
        ]
      }
    ]
  }
}

Resulting KSeF XML:

<tns:DodatkowyOpis>
  <tns:NrWiersza>1</tns:NrWiersza>
  <tns:Klucz>Color</tns:Klucz>
  <tns:Wartosc>Red</tns:Wartosc>
</tns:DodatkowyOpis>
<tns:DodatkowyOpis>
  <tns:NrWiersza>1</tns:NrWiersza>
  <tns:Klucz>Size</tns:Klucz>
  <tns:Wartosc>XL</tns:Wartosc>
</tns:DodatkowyOpis>

Note: Line-level DodatkowyOpis elements (with NrWiersza) are distinct from header-level ones (without NrWiersza). The sales order reference (BT-14) uses a header-level DodatkowyOpis, while additional item properties use line-level ones linked by their NrWiersza to the corresponding FaWiersz line number.

Special Property: unit_of_measure

Setting an additional item property with name unit_of_measure allows you to specify a free-text unit code for the line's P_8A field in KSeF, overriding the standard unit codelist. This is useful when the required unit is not available in the standard code list.

{
  "additional_item_properties_attributes": [
    { "name": "unit_of_measure", "value": "szt." }
  ]
}

This property is consumed directly as the line's unit code (Fa/FaWiersz/P_8A) and is not emitted as a DodatkowyOpis element in the XML output.

Taxes Mapping

All attributes listed in the following table are properties of objects contained in the array: invoice.invoice_lines_attributes[].taxes_attributes[]. The API Field column refers to keys within each tax object.

BT IDBusiness TermAPI Field (tax object)KSeF FA(3) Mapping
BT-118Tax Category Codecategory (check our code list)Used to derive P_12 tax code
BT-119Tax Rate Applicable PercentpercentUsed to derive P_12 tax code and P_13_x/P_14_x aggregations
BT-120Tax Exemption ReasoncommentFa/Adnotacje/Zwolnienie/P_19A

Tax Breakdown Aggregation (P_13_x / P_14_x)

KSeF requires tax amounts to be aggregated by rate at the header level. These fields are automatically computed from the invoice's tax breakdowns:

KSeF FieldDescriptionTax Rate / Category
P_13_1Taxable base at basic rate23% or 22%
P_14_1Tax amount at basic rate23% or 22%
P_14_1WTax amount at basic rate converted to PLN23% or 22% (foreign currency invoices only)
P_13_2Taxable base at first reduced rate8% or 7%
P_14_2Tax amount at first reduced rate8% or 7%
P_14_2WTax amount at first reduced rate converted to PLN8% or 7% (foreign currency invoices only)
P_13_3Taxable base at second reduced rate5%
P_14_3Tax amount at second reduced rate5%
P_14_3WTax amount at second reduced rate converted to PLN5% (foreign currency invoices only)
P_13_6_1Total value of domestic zero-rated sales0% domestic (excluding intra-EU and export)
P_13_6_2Total value of intra-Community supply of goods at 0%0% intra-EU goods
P_13_6_3Total value of exports at 0%0% export
P_13_7Total value of exempt salesExempt (category E, domestic scope)
P_13_8Total value of cross-border reverse charge (np I)Category AE, non-domestic scope
P_13_10Total value of domestic reverse chargeCategory AE, domestic scope
P_15Total amount due (inclusive of all taxes)Sum of all categories

Note: Fields P_14_xW (tax amounts converted to PLN) are only included for invoices in foreign currencies. The conversion uses the exchange_rate provided in the invoice.