ZATCA Technical

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.

Qeemah Team • Published: • Updated: • 11 min read
ZATCA Fatoora API Integration Developer Guide (2027): Endpoints, CSID & Clearance

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:

StepEndpointAuth / InputOutput
1POST /complianceHeader OTP: <6-digit> + Base64 ECDSA secp256k1 CSRCompliance CSID (binarySecurityToken, secret, requestID)
2POST /compliance/invoicesBasic Auth (CCSID:secret) + signed XML (invoiceHash, uuid, invoice)Pass 6 required compliance docs (388/381/383 × B2B/B2C)
3POST /production/csidsBasic Auth (CCSID:secret) + { "compliance_request_id": "..." }Production CSID (PCSID + secret) for live signing
4POST /invoices/clearance/singleBasic Auth (PCSID:secret) + Clearance-Status: 1Synchronous CLEARED B2B XML with ZATCA cryptographic stamp
5POST /invoices/reporting/singleBasic Auth (PCSID:secret) + locally signed B2C XMLREPORTED 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: V2
  • Accept-Language: en (or ar)
  • Content-Type: application/json
  • Authorization: Basic <Base64(PCSID_binarySecurityToken + ":" + secret)>
  • Clearance-Status: 1 (required on B2B clearance calls)

2. Common Fatoora API Pitfalls in Production

  1. HTTP 400 vs HTTP 202 (WARNING): A 202 response means the invoice cleared/reported with warnings—log every warningMessages code and fix before ZATCA upgrades warnings to blocking errors (browse our ZATCA BR-KSA Error Codes Directory).
  2. Broken PIH Hash Chain Under Concurrency: Concurrent requests per EGS unit must serialize ICV and PIH generation inside a database transaction or queue lock; otherwise Fatoora rejects out-of-order hashes.
  3. 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.
  4. CSID Certificate Expiry: Monitor Production CSID validity and automate renewal via PATCH /production/csids well 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.

Works Cited & Technical References

  1. Zakat, Tax and Customs Authority (ZATCA) — Fatoora Developer Portal & Integration Sandbox Documentation, zatca.gov.sa.

Recommended next steps

Share this article