ZATCA Fatoora API Integration Developer Guide (2027): Endpoints, CSID & Clearance
Technical 2027 developer playbook for ZATCA Fatoora API integration: sandbox vs simulation vs production endpoints, CSR/OTP onboarding, CCSID to PCSID exchange, clearance/reporting payloads, and error codes.
Summarize or verify this guide with AI:
Opens your preferred AI assistant with this article and ZATCA compliance context pre-loaded.
Quick Overview: The 5-Step Fatoora API Lifecycle (2027)
Every EGS unit (ERP tenant, branch, or POS register) integrating directly with the ZATCA Developer Portal (Fatoora) must implement five sequential REST steps across Sandbox, Simulation, and Production environments:
| Step | Endpoint | Auth / Input | Output |
|---|---|---|---|
| 1 | POST /compliance | Header OTP: <6-digit> + Base64 ECDSA secp256k1 CSR | Compliance CSID (binarySecurityToken, secret, requestID) |
| 2 | POST /compliance/invoices | Basic Auth (CCSID:secret) + signed XML (invoiceHash, uuid, invoice) | Pass 6 required compliance docs (388/381/383 × B2B/B2C) |
| 3 | POST /production/csids | Basic Auth (CCSID:secret) + { "compliance_request_id": "..." } | Production CSID (PCSID + secret) for live signing |
| 4 | POST /invoices/clearance/single | Basic Auth (PCSID:secret) + Clearance-Status: 1 | Synchronous CLEARED B2B XML with ZATCA cryptographic stamp |
| 5 | POST /invoices/reporting/single | Basic Auth (PCSID:secret) + locally signed B2C XML | REPORTED status within 24-hour SLA |
Before hitting /compliance/invoices, run your generated UBL 2.1 XML through our offline ZATCA XML Validator (BR-KSA Rule Checker) and verify your QR payload with our ZATCA QR Code Scanner & Decoder.
1. Required Request Payload & HTTP Headers
Both /invoices/clearance/single (Standard B2B 0100000) and /invoices/reporting/single (Simplified B2C 0200000) accept the exact same JSON body:
{
"invoiceHash": "<Base64 SHA-256 hash of canonicalized UBL XML>",
"uuid": "8e6000cf-1a98-4174-b3e7-b5d5954bc10d",
"invoice": "<Base64-encoded UTF-8 UBL 2.1 XML document>"
}
Mandatory HTTP headers:
Accept-Version: V2Accept-Language: en(orar)Content-Type: application/jsonAuthorization: Basic <Base64(PCSID_binarySecurityToken + ":" + secret)>Clearance-Status: 1(required on B2B clearance calls)
2. Common Fatoora API Pitfalls in Production
- HTTP 400 vs HTTP 202 (
WARNING): A202response means the invoice cleared/reported with warnings—log everywarningMessagescode and fix before ZATCA upgrades warnings to blocking errors (browse our ZATCA BR-KSA Error Codes Directory). - Broken
PIHHash Chain Under Concurrency: Concurrent requests per EGS unit must serializeICVandPIHgeneration inside a database transaction or queue lock; otherwise Fatoora rejects out-of-order hashes. - HTTP 429 Rate Limiting & Outage Retries: Implement exponential backoff and durable retry queues for simplified B2C reporting so every invoice settles inside the 24-hour window.
- CSID Certificate Expiry: Monitor Production CSID validity and automate renewal via
PATCH /production/csidswell before expiration.
3. Build vs Buy: Know Your Real Engineering Cost
Maintaining custom UBL 2.1 canonicalization, XAdES-BES UBLExtensions, ECDSA signing, and ongoing ZATCA SDK changes is a full-time reliability problem (see our ZATCA Phase 2 Implementation Cost Breakdown (2027)).
If your business wants native Phase 2 clearance, accounting, inventory, POS, and WPS payroll out of the box without maintaining cryptographic infrastructure, explore Qeemah ZATCA E-Invoicing or book a technical walkthrough.
Frequently Asked Questions
What are the main ZATCA Fatoora API endpoints for Phase 2?
The core REST endpoints are POST /compliance (request CCSID with CSR + OTP), POST /compliance/invoices (pass the 6 mandatory compliance checks), POST /production/csids (exchange CCSID for Production CSID), POST /invoices/clearance/single (B2B real-time clearance), and POST /invoices/reporting/single (B2C simplified reporting within 24 hours).
What HTTP headers are required when calling ZATCA clearance and reporting APIs?
Every call requires Accept-Version: V2, Accept-Language: en (or ar), Content-Type: application/json, Authorization: Basic <base64(binarySecurityToken:secret)>, and Clearance-Status: 1 for B2B clearance requests.
Should we build a custom Fatoora API integration or use a native ERP?
Building and maintaining ECDSA signing, distributed PIH locking, CSID renewal, and SDK updates typically costs SAR 90,000–250,000+. Unless you run a bespoke high-volume billing platform, adopting a native Saudi cloud ERP like Qeemah Cloud eliminates the engineering burden.