Guida rapida
Validi la Sua prima fattura elettronica tramite l'API in circa cinque minuti.
1. Crei un account gratuito e una chiave di test
Acceda a https://einvoiceengine.com/login con il Suo indirizzo e-mail. Apra API keys e crei una chiave di test. Inizia con einv_test_ e viene mostrata una sola volta: la conservi nel Suo secret manager.
Le chiavi di test eseguono il vero motore di validazione. Sono gratuite, non vengono mai fatturate e sono limitate alla quota sandbox del Suo piano.
export EINV_BASE=https://einvoiceengine.com
export EINV_KEY=einv_test_...
2. Validi una fattura
Invii l'XML come corpo della richiesta. Funziona qualsiasi documento XRechnung 3.0 o EN 16931 in UBL o CII, così come un PDF ZUGFeRD / Factur-X (Content-Type: application/pdf).
validate.sh
#!/usr/bin/env bash
# Validate an invoice with curl.
# EINV_BASE: API base URL (e.g. https://einvoicing.example.com); EINV_KEY: your API key.
set -euo pipefail
curl -sS --fail-with-body "$EINV_BASE/v1/invoices/validate" \
-H "Authorization: Bearer $EINV_KEY" \
-H "Content-Type: application/xml" \
--data-binary @"${1:-invoice.xml}"
Non ha una fattura a portata di mano? Scarichi l'esempio ufficiale o l'esempio con errori.
Oppure lasci che sia l'API a creare fatture di test per Lei. POST /v1/testdata restituisce fatture sintetiche nel formato indicato, sia valide sia con errori tipici, ciascuna già verificata con le regole ufficiali. Non viene fatturato e nulla viene archiviato.
curl -X POST $EINV_BASE/v1/testdata \
-H "Authorization: Bearer $EINV_KEY" -H "Content-Type: application/json" \
-d '{ "target": "xrechnung-ubl" }'
Ogni caso contiene name, filename, document, expected e actual. GET /v1/testdata/cases elenca i casi e i formati di destinazione.
3. Legga il risultato
{
"status": "invalid",
"valid": false,
"detected": { "format": "xrechnung-ubl", "syntax": "ubl", "profile": "XRechnung", "version": "3.0" },
"summary": { "errors": 2, "warnings": 0, "infos": 1 },
"findings": [
{
"severity": "error",
"ruleId": "BR-DE-15",
"message": "[BR-DE-15] Das Element \"Buyer reference\" (BT-10) muss übermittelt werden.",
"explanation": "XRechnung requires the buyer reference (BT-10). For German public buyers this is the Leitweg-ID.",
"suggestion": "Set cbc:BuyerReference (UBL) or ram:BuyerReference (CII) to the Leitweg-ID or reference supplied by the buyer.",
"location": { "path": "/Invoice", "line": 2, "column": 1 }
}
]
}
statusèvalid,invalidounsupported. Lo determinano solo i set di regole ufficiali.messageè il testo ufficiale della regola, alla lettera.explanationesuggestionlo riformulano in linguaggio semplice.- I risultati sono disponibili in inglese, tedesco, francese, spagnolo, italiano, polacco, olandese o portoghese: aggiunga
?lang=it(oppureen,de,fr,es,pl,nl,pt) o inviiAccept-Language. Il testo ufficiale della regola resta inmessage;messageTranslationaggiunge una traduzione non ufficiale quando è disponibile. coverageelenca esattamente quali set di regole sono stati eseguiti e cosa non è stato verificato.
4. Lo stesso in TypeScript e Python
validate.ts
// Validate an invoice with TypeScript (Node 20+, no dependencies).
// Run: EINV_BASE=… EINV_KEY=… npx tsx validate.ts invoice.xml
import { readFile } from "node:fs/promises";
const base = process.env.EINV_BASE!;
const key = process.env.EINV_KEY!;
const xml = await readFile(process.argv[2] ?? "invoice.xml");
const res = await fetch(`${base}/v1/invoices/validate`, {
method: "POST",
headers: { authorization: `Bearer ${key}`, "content-type": "application/xml" },
body: xml,
});
if (!res.ok) {
const { error } = await res.json();
throw new Error(`${error.code}: ${error.message} (request ${error.requestId})`);
}
const result = await res.json();
console.log(result.status, `${result.summary.errors} errors`);
for (const f of result.findings.filter((f: { severity: string }) => f.severity === "error")) {
console.log(`- ${f.ruleId}: ${f.explanation} (line ${f.location?.line ?? "?"})`);
}
validate.py
"""Validate an invoice with Python (standard library only).
Run: EINV_BASE=... EINV_KEY=... python3 validate.py invoice.xml
"""
import json
import os
import sys
import urllib.error
import urllib.request
base = os.environ["EINV_BASE"]
key = os.environ["EINV_KEY"]
path = sys.argv[1] if len(sys.argv) > 1 else "invoice.xml"
with open(path, "rb") as f:
body = f.read()
req = urllib.request.Request(
f"{base}/v1/invoices/validate",
data=body,
method="POST",
headers={"Authorization": f"Bearer {key}", "Content-Type": "application/xml"},
)
try:
with urllib.request.urlopen(req, timeout=60) as resp:
result = json.load(resp)
except urllib.error.HTTPError as e:
err = json.load(e)["error"]
sys.exit(f"{err['code']}: {err['message']} (request {err['requestId']})")
print(result["status"], f"{result['summary']['errors']} errors")
for f in result["findings"]:
if f["severity"] == "error":
line = (f.get("location") or {}).get("line", "?")
print(f"- {f['ruleId']}: {f['explanation']} (line {line})")
E-Invoicing API