Inicio rápido
Valide su primera factura electrónica a través de la API en unos cinco minutos.
1. Cree una cuenta gratuita y una clave de prueba
Inicie sesión en https://einvoiceengine.com/login con su dirección de correo electrónico. Abra Claves API y cree una clave de prueba. Empieza por einv_test_ y se muestra una sola vez: guárdela en su gestor de secretos.
Las claves de prueba utilizan el motor de validación real. Son gratuitas, nunca se facturan y están limitadas a la cuota sandbox de su plan.
export EINV_BASE=https://einvoiceengine.com
export EINV_KEY=einv_test_...
2. Valide una factura
Envíe el XML como cuerpo de la solicitud. Sirve cualquier documento XRechnung 3.0 o EN 16931 en UBL o CII, y también 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}"
¿No tiene ninguna factura a mano? Descargue el ejemplo oficial o el ejemplo con errores.
O deje que la API cree facturas de prueba por usted. POST /v1/testdata devuelve facturas sintéticas en el formato que indique, válidas y con errores típicos, cada una ya comprobada con las reglas oficiales. No se factura y no se guarda nada.
curl -X POST $EINV_BASE/v1/testdata \
-H "Authorization: Bearer $EINV_KEY" -H "Content-Type: application/json" \
-d '{ "target": "xrechnung-ubl" }'
Cada caso tiene name, filename, document, expected y actual. GET /v1/testdata/cases enumera los casos y los formatos de destino.
3. Lea el resultado
{
"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 }
}
]
}
statusesvalid,invalidounsupported. Solo lo deciden los conjuntos de reglas oficiales.messagees el texto oficial de la regla, literal.explanationysuggestionlo reformulan en lenguaje sencillo.- Los resultados están disponibles en inglés, alemán, francés, español, italiano, polaco, neerlandés o portugués: añada
?lang=de(oen,fr,es,it,pl,nl,pt) o envíeAccept-Language. El texto oficial de la regla permanece enmessage;messageTranslationañade una traducción no oficial cuando existe. coverageenumera exactamente qué conjuntos de reglas se ejecutaron y qué no se comprobó.
4. Lo mismo en TypeScript y 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