Embedded validation widget
Put the e-invoice check into your own product: your users drop an invoice and see the official result, the explanation and how to fix it — in their language, in your colours. You build no upload or report screen.
Your API key never reaches the browser. Your backend creates a short-lived widget session; the page only gets the session's URL. A session works for one site (origin), for a limited number of checks and for at most an hour, and can do nothing but validate — no history, no keys, no other operations.
1. Create a session on your server
curl -X POST https://einvoiceengine.com/v1/widget/sessions \
-H "Authorization: Bearer $EINV_KEY" -H "Content-Type: application/json" \
-d '{ "origin": "https://app.example.com", "maxDocuments": 20, "ttlMinutes": 15, "lang": "de", "accent": "#0a7d55", "theme": "auto" }'
| Field | Meaning |
|---|---|
origin |
the https origin of the page that shows the widget; no other site can frame it |
maxDocuments |
checks allowed in this session, 1–100 (default 20) |
ttlMinutes |
lifetime, 1–60 (default 15) |
lang |
en, de, fr, es, it, pl, nl or pt — interface and explanations |
accent, theme |
your colour (#rrggbb) and light, dark or auto |
The response has url (and token, expiresAt). Create a new session per page view or per user; do not cache it.
2. Show it
einv-widget.js
// Embeds the E-Invoicing validation widget. Load this file on your page, then:
// EinvWidget.mount(document.getElementById("check"), {
// sessionUrl: "/api/einvoice-widget-session", // YOUR backend: creates a session, returns { url }
// onResult: (r) => console.log(r.status, r.summary, r.ruleIds),
// onError: (e) => console.warn(e.code),
// });
// Your API key stays on your server; the browser only ever sees a short-lived session URL.
(function (global) {
function mount(el, opts) {
var frame = document.createElement("iframe");
frame.title = opts.title || "E-invoice check";
frame.style.cssText = "width:100%;border:0;min-height:" + (opts.minHeight || 420) + "px";
frame.setAttribute("sandbox", "allow-scripts allow-same-origin allow-downloads");
el.appendChild(frame);
var apiOrigin = null;
function onMessage(e) {
if (e.source !== frame.contentWindow || e.origin !== apiOrigin) return;
var m = e.data || {};
if (m.type === "einv:result" && opts.onResult) opts.onResult(m);
if (m.type === "einv:error" && opts.onError) opts.onError(m);
if (m.type === "einv:ready" && opts.onReady) opts.onReady();
}
window.addEventListener("message", onMessage);
fetch(opts.sessionUrl, { method: "POST", credentials: "same-origin" })
.then(function (r) { return r.json(); })
.then(function (s) {
apiOrigin = new URL(s.url).origin;
frame.src = s.url;
})
.catch(function () { if (opts.onError) opts.onError({ code: "session_failed" }); });
return { destroy: function () { window.removeEventListener("message", onMessage); frame.remove(); } };
}
global.EinvWidget = { mount: mount };
})(window);
With React:
import { useEffect, useRef } from "react";
export function InvoiceCheck({ onResult }: { onResult: (r: { status: string; ruleIds: string[] }) => void }) {
const el = useRef<HTMLDivElement>(null);
useEffect(() => {
const w = (window as any).EinvWidget.mount(el.current, { sessionUrl: "/api/einvoice-widget-session", onResult });
return () => w.destroy();
}, []);
return <div ref={el} />;
}
Events
The widget sends postMessage events to your page only: einv:ready; einv:result with status, summary, format and ruleIds; einv:error with code (widget_session_expired, widget_session_used_up, network, …).
Checks count and are billed like API validations of the key that created the session (shown as widget usage). Documents are processed in memory and not stored.
What the session URL is
url points to /embed/<token> on our site, a page that only the session's origin may frame. The page sends each file to POST /embed/<token>/validate. Both work only with a valid session token and are not part of the REST API: do not call them from your server, use POST /v1/invoices/validate there. Files up to 2 MB are accepted. Errors: 401 widget_session_expired, 429 widget_session_used_up (see errors).
E-Invoicing API