POST /v1/generate/ubl — exemples par langage
Variantes disponibles :
fr-socle,peppol-bis,xrechnung(depuis Story 13.2 — voir XRechnung Allemagne pour ce que cette variante couvre et ne couvre pas).
Requête : même JSON que POST /v1/generate/facturx (modèle pivot EN 16931).
Réponse : XML UBL 2.1 brut.
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 @ma-facture.json \
-o facture.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('ma-facture.json'),
CURLOPT_RETURNTRANSFER => true,
]);
$ublXml = curl_exec($ch);
file_put_contents('facture.ubl.xml', $ublXml);
Python
import requests, os
with open("ma-facture.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("facture.ubl.xml", "wb") as out:
out.write(resp.content)
JavaScript (Node.js)
import { readFile, writeFile } from "node:fs/promises";
const invoice = await readFile("ma-facture.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("facture.ubl.xml", Buffer.from(await resp.arrayBuffer()));
Go
package main
import (
"net/http"
"os"
)
func main() {
f, _ := os.Open("ma-facture.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("facture.ubl.xml")
defer out.Close()
_, _ = out.ReadFrom(resp.Body)
}
⚠️ Ce que la conformité UBL signifie aujourd'hui
Le XML produit est structurellement bien formé et suit le même modèle pivot EN 16931 que Factur-X/CII, mais aucun rule pack UBL officiel n'est encore intégré (pas de vérification XSD/schematron Peppol BIS réelle à ce stade). Voir Peppol Belgique pour le détail de cet écart.