POST /v1/generate/ubl — examples by language
Available variants:
fr-socle,peppol-bis,xrechnung(since Story 13.2 — see XRechnung Germany for what this variant covers and does not cover).
Request: the same JSON as POST /v1/generate/facturx (EN 16931 pivot model).
Response: raw UBL 2.1 XML.
curl
curl -X POST "https://api.example/v1/generate/ubl?variant=peppol-bis" \
-H "Authorization: Bearer $FACTURX_API_KEY" \
-H "Content-Type: application/json" \
-d @my-invoice.json \
-o invoice.ubl.xml
PHP
<?php
$ch = curl_init('https://api.example/v1/generate/ubl?variant=fr-socle');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('FACTURX_API_KEY'),
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => file_get_contents('my-invoice.json'),
CURLOPT_RETURNTRANSFER => true,
]);
$ublXml = curl_exec($ch);
file_put_contents('invoice.ubl.xml', $ublXml);
Python
import requests, os
with open("my-invoice.json", "rb") as f:
resp = requests.post(
"https://api.example/v1/generate/ubl",
params={"variant": "peppol-bis"},
headers={"Authorization": f"Bearer {os.environ['FACTURX_API_KEY']}", "Content-Type": "application/json"},
data=f,
)
with open("invoice.ubl.xml", "wb") as out:
out.write(resp.content)
JavaScript (Node.js)
import { readFile, writeFile } from "node:fs/promises";
const invoice = await readFile("my-invoice.json");
const resp = await fetch("https://api.example/v1/generate/ubl?variant=fr-socle", {
method: "POST",
headers: { Authorization: `Bearer ${process.env.FACTURX_API_KEY}`, "Content-Type": "application/json" },
body: invoice,
});
await writeFile("invoice.ubl.xml", Buffer.from(await resp.arrayBuffer()));
Go
package main
import (
"net/http"
"os"
)
func main() {
f, _ := os.Open("my-invoice.json")
defer f.Close()
req, _ := http.NewRequest(http.MethodPost, "https://api.example/v1/generate/ubl?variant=peppol-bis", f)
req.Header.Set("Authorization", "Bearer "+os.Getenv("FACTURX_API_KEY"))
req.Header.Set("Content-Type", "application/json")
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
out, _ := os.Create("invoice.ubl.xml")
defer out.Close()
_, _ = out.ReadFrom(resp.Body)
}
⚠️ What UBL compliance means today
The generated XML is structurally well-formed and follows the same EN 16931 pivot model as Factur-X/CII, but no official UBL rule pack is integrated yet (no real Peppol BIS XSD/schematron check at this stage). See Peppol Belgium for the detail of this gap.