# GCC e-Invoice Preflight Oracle (`thenightowl/einvoice-preflight`) Actor

Validate UAE and Saudi e-invoices before submission: UBL 2.1 schema, the official PINT AE 1.0.3 Schematron incl. UAE rules, FTA field checks, ZATCA UBL rules and QR/TLV decoding. Rule ids, fields, fix hints, batch readiness reports with HTML. $0.015 per document. MCP server + REST. No logging.

- **URL**: https://apify.com/thenightowl/einvoice-preflight.md
- **Developed by:** [Mohamad Najia](https://apify.com/thenightowl) (community)
- **Features:** Limited permissions, Single-tenant, Server interface
- **Stats:** 1 total users, 0 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $15.00 / 1,000 document validateds

This Actor is paid per event and usage. You are charged both the fixed price for specific events and for Apify platform usage.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## GCC e-Invoice Preflight Oracle — validate UAE (PINT AE) and Saudi (ZATCA) e-invoices before you send them

**Will this invoice be accepted?** Paste the UBL XML and get a verdict in under 100 ms, with every failing rule by its
official id, the fields involved, where it is in the document, and a plain-language fix.

The UAE's e-invoicing mandate goes live on **1 January 2027** (large businesses) and **1 July 2027** (everyone else);
Saudi Arabia's ZATCA integration waves continue through 2027. Accredited Service Providers reject non-conforming
documents — this tool runs the same published rules first, so your ERP, integration or AI agent fixes the invoice
*before* it costs a rejection (or an AED 100 per-invoice penalty).

### What is checked

| jurisdiction | checks | rule ids |
|---|---|---|
| **UAE — PINT AE Billing 1.0.3** (`ae`) | UBL 2.1 schema · the **official OpenPeppol Schematron** (shared PINT rules + the UAE jurisdiction overlay, ≈300 rules, run unmodified with Saxon-HE) · advisory cross-checks: 15-digit TRN, TIN = first 10 digits (Peppol scheme 0235), emirate codes, 5 % VAT rate, totals arithmetic, dates, duplicate lines, attachment size | `ibr-…`, `ibr-…-ae`, `nae-…` |
| **UAE — PINT AE Self-Billing 1.0.3** (`ae-sb`) | same, with the self-billing rule set | |
| **Saudi Arabia — ZATCA** (`sa`) | UBL 2.1 schema · profile, UUID, invoice type + subtype, ICV / PIH / QR references, VAT-number format, national address, SAR, dates, totals · **QR TLV decoded and compared with the document** | `nksa-…` |

Every finding: `{"id": "ibr-co-16", "severity": "fatal", "message": "Amount due for payment (ibt-115) = …", "fields": ["IBT-112","IBT-113","IBT-115"], "location": "/Invoice/LegalMonetaryTotal", "fix_hint": "PayableAmount = TaxInclusiveAmount - PrepaidAmount …", "source": "schematron"}`.
Verdicts: `ACCEPTED` · `ACCEPTED_WITH_WARNINGS` · `REJECTED`.

### Tools

| tool | what | price |
|---|---|---|
| `validate_invoice` | one Invoice / CreditNote, full pipeline, jurisdiction auto-detected | $0.015 |
| `readiness_report` | up to 100 documents → verdicts, readiness %, most frequent rejection rules, optional printable HTML | $0.015 / document |
| `extract_summary` | seller/buyer/TRN/endpoint, totals, VAT breakdown, line count — no validation | free |
| `list_rules` | the official PINT AE rule texts, filterable, with our fix hints | free |
| `check_trn` | UAE TRN format + derived TIN / Peppol participant id `0235:…` | free |
| `zatca_qr_decode` / `zatca_qr_encode` | ZATCA QR TLV ↔ fields (phase 1 and 2 tags) | free |

**Run it** on Apify with a batch of XML files and download `REPORT.html` for the go-live meeting; **call it** from an AI
agent as an MCP server; or **POST** to the REST API from your ERP's outbound queue.

### Example

```json
// validate_invoice {"xml": "<Invoice …>", "jurisdiction": "auto"}
{"result": {"verdict": "REJECTED", "jurisdiction": "ae", "ruleset": "PINT AE Billing 1.0.3 (2026-03-25)", "document_id": "INV-2026-0142",
  "findings": [
    {"id": "ibr-co-16", "severity": "fatal", "message": "Amount due for payment (ibt-115) = Invoice total amount with Tax (ibt-112) - Paid amount (ibt-113)",
     "fields": ["IBT-112", "IBT-113", "IBT-115"], "location": "/Invoice/LegalMonetaryTotal", "fix_hint": "PayableAmount = TaxInclusiveAmount - PrepaidAmount (+ PayableRoundingAmount).", "source": "schematron"},
    {"id": "ibr-141-ae", "severity": "fatal", "message": "When, VAT point date [IBT-007] is present, it should be before the Invoice issue date [IBT-002].",
     "fields": ["IBT-002", "IBT-007"], "location": "/Invoice", "fix_hint": "VAT point date (TaxPointDate) must be on or before the issue date.", "source": "schematron"},
    {"id": "nae-011", "severity": "warning", "message": "Seller EndpointID (scheme 0235) '1111111111' is not the first 10 digits of the TRN '100123456700003'.", "fields": ["IBT-031", "IBT-034"], "source": "preflight"}],
  "counts": {"fatal": 2, "warning": 1, "info": 0}, "billable_documents": 1},
 "data_confidence": "high", "estimated_items": ["findings with source=preflight are advisory cross-checks, not official Schematron rules"],
 "sources": ["https://docs.peppol.eu/poac/ae/v1.0.3/pint-ae/", "https://docs.oasis-open.org/ubl/os-UBL-2.1/", "https://mof.gov.ae/einvoicing/"],
 "disclaimer": "Preflight check against the published PINT AE / UBL / ZATCA rules. It is not acceptance …"}
```

### Honest limits

- **Preflight, not clearance.** The Accredited Service Provider / FTA / ZATCA decide. We run the published rules exactly
  as published and tell you which version; rule sets change (PINT AE 1.0.3 changed ~30 rules in March 2026) and we update.
- **Saudi coverage is a curated subset** (`data_confidence: medium`): the common structural rejections plus QR consistency.
  Signing, hashing and clearance stay with your compliance CSID and the ZATCA SDK.
- **UBL only.** No PDF, no OCR, no JSON-to-UBL conversion (ask — that is a natural next tool).
- The official artefacts (OpenPeppol Schematron, OASIS UBL schemas) are fetched into the image at build time from their
  official URLs, SHA-256-pinned; they are not redistributed with this code.

### Connect

- **Apify:** run from the Console (paste XML or a JSON list) or Standby URL + `/mcp` with `Authorization: Bearer <your Apify token>`.
- **Self-hosted:** `claude mcp add einvoice --transport http https://einvoice.noahsarch.tech/mcp --header "X-API-Key: <key>"`
- **REST:** `POST https://einvoice.noahsarch.tech/v1/tools/validate_invoice` with `{"xml": "..."}`; OpenAPI at `/openapi.json`.
- **On-premises:** the same container runs inside your network with no outbound connections — ask for a licence.

### Built on

OpenPeppol [PINT AE](https://docs.peppol.eu/poac/ae/v1.0.3/pint-ae/) artefacts · [OASIS UBL 2.1](https://docs.oasis-open.org/ubl/os-UBL-2.1/) ·
[Saxon-HE](https://www.saxonica.com/) (XSLT 2.0, MPL 2.0) · lxml · [ZATCA e-invoicing standards](https://zatca.gov.sa/en/E-Invoicing/SystemsDevelopers/Pages/default.aspx).

***

### بالعربية

**مدقّق الفواتير الإلكترونية الخليجي** — تحقّق من فاتورتك الإلكترونية قبل إرسالها إلى مزوّد الخدمة المعتمد: مخطط UBL 2.1،
قواعد Schematron الرسمية لمعيار PINT AE 1.0.3 (الإمارات) بما فيها قواعد الولاية الإماراتية، فحوصات حقول الهيئة الاتحادية
للضرائب (رقم التسجيل الضريبي، معرّف Peppol، رموز الإمارات، نسبة 5٪، المجاميع)، وفحوصات هيئة الزكاة والضريبة والجمارك
(السعودية) مع فكّ رمز QR ومطابقته بالفاتورة. تحصل على حكم واضح وكل قاعدة فاشلة برقمها الرسمي والحقول المعنية واقتراح الإصلاح،
وتقرير جاهزية HTML لمجموعة فواتير كاملة. 0.015 دولار للمستند. لا تُخزَّن المستندات ولا تُسجَّل. ليس بديلاً عن قرار مزوّد
الخدمة أو الهيئة.

# Changelog

This Actor's version history is a separate document: https://apify.com/thenightowl/einvoice-preflight/changelog.md

# Actor input Schema

## `xml` (type: `string`):

One UBL 2.1 Invoice or CreditNote (PINT AE or ZATCA).

## `documents` (type: `array`):

List of {"name": "INV-1.xml", "xml": "\<Invoice …>"} objects, up to 5,000 per run.

## `jurisdiction` (type: `string`):

auto (from CustomizationID/ProfileID), ae (PINT AE Billing), ae-sb (PINT AE Self-Billing) or sa (ZATCA).

## `preflight` (type: `boolean`):

Also run the Noah's Arch advisory checks (TRN/TIN consistency, emirate codes, VAT rate, totals, dates).

## Actor input object example

```json
{
  "jurisdiction": "auto",
  "preflight": true
}
```

# Actor output Schema

## `results` (type: `string`):

No description

## `report` (type: `string`):

No description

## `mcpEndpoint` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {};

// Run the Actor and wait for it to finish
const run = await client.actor("thenightowl/einvoice-preflight").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {}

# Run the Actor and wait for it to finish
run = client.actor("thenightowl/einvoice-preflight").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{}' |
apify call thenightowl/einvoice-preflight --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,thenightowl/einvoice-preflight"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/zZMVyFgj076ZLdGm1/builds/lYNTlJvDTVtKfvBW5/openapi.json
