ZATCA e-invoicing (Fatoora) integration for your system
Phase 2 means your system signs every invoice as XML and exchanges it with ZATCA's Fatoora platform through its APIs: B2B tax invoices are cleared before the buyer receives them, and B2C simplified invoices are reported within 24 hours. Most of the work is onboarding each invoicing unit, getting the XML and signature right, and handling rejections.
Updated
ZATCA’s e-invoicing regulation has two phases. Phase 1 (generation and storage) began on 4 December 2021 and requires invoices to be issued electronically from a compliant solution. Phase 2 (integration) adds three things: your solution connects to ZATCA’s Fatoora platform, issues invoices in a specified XML format, and includes extra technical fields such as a cryptographic stamp, an invoice hash and an expanded QR code.
This guide is written from the developer’s side. It covers what your system has to do, in what order, and where integrations usually fail, so you can scope the work or judge a vendor’s proposal. The legal obligation and the final word on every detail stay with ZATCA’s own documents, linked throughout.
Who has to integrate, and when
ZATCA rolls Phase 2 out in waves. Each wave is defined by VAT-taxable revenue in specific years, and ZATCA notifies the taxpayers in a wave directly, at least six months before their integration date.
The most recent wave at the time of writing is Wave 25. In its announcement of 24 July 2026, ZATCA says it covers taxpayers whose VAT-taxable revenue exceeded SAR 187,500 in any of 2022, 2023, 2024 or 2025, and that they must integrate by 1 February 2027. Earlier waves had higher thresholds, so the pool now reaches many small and mid-sized businesses.
Three practical points:
- The notification is what counts. Don’t decide from a blog summary, this one included. Check what ZATCA sent you and what the Fatoora portal shows for your VAT number.
- Six months is not long for a custom system. Onboarding, XML and signing work, testing and a cut-over plan all fit, but not if you start in the last month.
- Your invoicing software may already cover it. If invoices come out of an accounting, ERP or POS product, ask the vendor how it handles Phase 2 before you plan any development.
The pieces you will deal with
ZATCA’s Detailed Technical Guideline uses a few terms you will see everywhere:
| Term | What it means for your system |
|---|---|
| EGS unit | An E-invoice Generation Solution unit: each device or server that generates and signs invoices. A POS terminal, a branch server or a central invoicing service can each be one. |
| Fatoora portal | ZATCA’s web portal where the taxpayer manages onboarding: generating one-time passwords, viewing onboarded units, renewing and revoking certificates. |
| Fatoora platform | The API back end that receives, validates and stores your invoices. |
| CSID | Cryptographic Stamp Identifier, a certificate ZATCA issues to an EGS unit. There is a compliance CSID for onboarding tests and a production CSID for live invoices. |
| Developer Portal | ZATCA’s portal for developers, with the Compliance and Enablement Toolbox (SDK) and an integration sandbox. |
A design decision sits behind the first row: where does signing happen? ZATCA’s guideline allows “dumb” POS terminals with no CSID of their own, as long as the server that signs and applies the QR code before the invoice reaches the customer holds one. A central signing service is usually simpler to secure and renew than a certificate on every device.
Onboarding an EGS unit
Onboarding is a one-time process per unit, repeated when its certificate is renewed. In ZATCA’s order:
- Generate an OTP on the Fatoora portal. The taxpayer can generate up to 100 one-time passwords in one request, for onboarding several units at once. Each OTP is valid for one hour.
- Create a key pair and a CSR. The unit generates its private and public keys and builds a certificate signing request with the fields ZATCA specifies: VAT number, unit identifiers, branch, industry and the invoice types the unit will issue. ZATCA notes that every CSR field is mandatory and a malformed one is rejected.
- Receive a compliance CSID. The unit sends the CSR with the OTP, and ZATCA returns a compliance certificate.
- Pass the compliance checks. Using that certificate, the unit submits sample documents for each invoice type it declared. For standard (B2B) that is a tax invoice, a debit note and a credit note; for simplified (B2C) it is the same three. If a test fails, the process starts again from a new OTP.
- Receive a production CSID. This certificate signs and authenticates live submissions. It has an expiry date, and the renewal follows the same steps, revoking the old certificate when the new one is issued.
The private key never leaves your system, so treat it like any other production secret: stored encrypted, out of source code and logs, and readable only by the signing service.
Clearance vs. reporting
This is the part that shapes your invoice flow, because the two models put ZATCA in a different place in the transaction.
| Clearance | Reporting | |
|---|---|---|
| Applies to | Standard tax invoices and their credit/debit notes (generally B2B) | Simplified tax invoices and their credit/debit notes (generally B2C) |
| When you submit | Before the buyer receives the invoice | Within 24 hours of issuing it |
| Who stamps it | ZATCA stamps it and returns it with a QR code | Your EGS signs it and adds the QR code itself |
| Valid when | It carries ZATCA’s clearance stamp | It is issued from your compliant EGS; reporting confirms it |
| Response | The cleared XML, plus any warnings | A confirmation, plus any warnings |
Both return one of three outcomes: valid, accepted with warnings, or rejected with errors. Warnings still need fixing in later documents, because an accepted-with-warnings document is not fully compliant.
Two details trip teams up:
- Clearance sits in the checkout path. For B2B, your system cannot hand over the invoice until ZATCA answers, so a slow or failed call is visible to staff or customers. Design the screen and the retry for that.
- Clearance can be switched off. ZATCA’s guideline says that when clearance is disabled, the clearance API answers with a redirect status and standard documents go to the reporting API instead. Handle that response rather than treating it as an error.
The XML, the hash chain and the QR code
Phase 2 documents are UBL-based XML, following ZATCA’s XML implementation standard and data dictionary, published with its technical requirements. The buyer can receive XML or a PDF/A-3 file with the XML embedded, but ZATCA itself only accepts the XML.
What your code has to get right:
- A unique ID and a counter. Each document carries a UUID and an invoice counter value (ICV). A counter value is never reused, even for a rejected document.
- The previous invoice hash. Each unit keeps one sequence across both standard and simplified documents. Every document includes the hash of the last document that unit generated, including rejected ones, because ZATCA records their hashes too. Documents can arrive at ZATCA out of order, as long as each one points to the right predecessor.
- The signature. The guideline specifies a SHA-256 hash of the invoice, with certain elements removed first, signed with ECDSA using the unit’s private key. ZATCA’s stamp and QR string are not part of that hash, so you don’t need to wait for one invoice to clear before generating the next.
- The QR code. A Base64 string of TLV (tag-length-value) fields, up to 700 characters. Phase 1 required five tags: seller name, VAT number, timestamp, invoice total and VAT total. Phase 2 adds the XML hash, the ECDSA signature and the public key, and for simplified invoices a ninth tag: ZATCA’s signature over your certificate’s public key.
Most rejections in practice come from small mismatches here: rounding between line items and totals, a missing buyer field on a standard invoice, a hash taken over the wrong canonical form, or a counter reset after a deployment.
Testing before you go live
ZATCA gives you more than one place to test, and they are separate from production:
- The Compliance and Enablement Toolbox. An offline SDK on the Developer Portal that validates XML documents and QR codes, with a command-line interface you can run in CI. Run every invoice template through it before you touch an API.
- The integration sandbox. A test back end with the API documentation and Swagger files, where you can simulate onboarding and submit standard and simplified test documents.
- The simulation environment. A replica of the live Fatoora flow for taxpayers to run their real setup end to end without issuing official invoices. Onboarding there does not carry over: production needs its own OTP, CSR and certificates.
Test the unhappy paths as well as the happy one: a rejected invoice followed by the next one in the chain, a credit note that references its original invoice, a timeout during clearance, an expired certificate, and a restart in the middle of a batch.
Plan for failure from the start
ZATCA’s detailed guidelines describe what is expected when submission fails, and your design should follow them:
- ZATCA not responding. Keep retrying the same document at regular intervals and log each attempt. For B2B, ZATCA’s examples allow sharing the uncleared invoice with the buyer and keeping the transaction records while you retry, then sending the cleared version once clearance succeeds.
- No connection on your side. Simplified invoices still have the 24-hour window. If you can’t make it, notify ZATCA through the form on its website, and again when the connection is back.
- A rejected document. Fix the cause and issue a new document with a new counter. Don’t edit and resend the rejected one.
- Certificate expiry. Track every unit’s expiry date and renew ahead of it. A unit signing with an invalid certificate gets every invoice rejected.
A queue between invoice creation and submission, an alert when anything sits in it too long, and a dashboard of rejections and warnings cover most of this. Without them, problems surface at VAT return time.
Build it, or let your software do it
| Your situation | Usually the sensible route |
|---|---|
| Invoices come from accounting, ERP or POS software | Ask the vendor about Phase 2 and use its integration. |
| You sell through a store platform (Salla, Zid or a custom store) | Check what the platform and your invoicing app provide before building anything. |
| Invoices are generated inside your own platform (bookings, subscriptions, a SaaS product) | Integrate the platform directly, or route its invoices through an invoicing product that already integrates. |
| Several systems issue invoices | Decide which system is the single issuer per transaction type before writing code. |
Building it yourself is not one sprint and done. ZATCA updates its specifications, certificates expire, and every new invoice type or branch means another onboarding. Whoever builds it should also own those updates.
How Bahr AI approaches this
Bahr AI is a software and AI company in Jeddah. We integrate business systems with ZATCA’s Fatoora platform for Phase 2, and we have delivered these integrations. The work covers everything in this guide: onboarding each EGS unit and managing its certificates, generating and signing the XML, clearance and reporting, and the queue, alerts and dashboard that catch rejections before VAT return time.
We usually start where your invoices are created. That may be a website or platform with bookings, subscriptions or a dashboard, or a set of tools that already pass work between them, which is where our workflow automation habits help: trace how the work moves today, document each step, and add an alert when one fails.
Cost follows scope, so we quote after we understand the project.
If you’re scoping a Phase 2 integration, tell us about your system: where invoices are created today, which invoice types you issue, and your wave’s integration date.
Frequently asked questions
How do I know if my business is in a Phase 2 wave?
ZATCA selects each wave by VAT-taxable revenue in set years and notifies the taxpayers in it directly, at least six months before their integration date. Wave 25, announced on 24 July 2026, covers taxpayers whose VAT-taxable revenue exceeded SAR 187,500 in any of 2022, 2023, 2024 or 2025, with integration due by 1 February 2027. Check your notification and the Fatoora portal rather than relying on a summary.
What is the difference between clearance and reporting?
Clearance applies to standard tax invoices and their credit and debit notes, usually B2B. You send the XML to ZATCA first, ZATCA stamps it and returns it with a QR code, and only then is it valid to give to the buyer. Reporting applies to simplified tax invoices and their notes, usually B2C. Your system signs the invoice and adds the QR code itself, gives it to the customer, and submits the XML to ZATCA within 24 hours.
What is a CSID and how do I get one?
A CSID (Cryptographic Stamp Identifier) is a certificate ZATCA issues to each e-invoicing unit, such as a POS device or an invoicing server. You generate a one-time password on the Fatoora portal, your unit sends a certificate signing request and receives a compliance CSID, passes the compliance checks by submitting sample documents, and then receives a production CSID. CSIDs expire and must be renewed before the expiry date.
Can we send PDF invoices to ZATCA?
No. Phase 2 documents are submitted to Fatoora as XML. A PDF/A-3 file with the XML embedded is allowed when you share an invoice with the buyer, but the copy sent to ZATCA for clearance or reporting must be the XML.
What happens if ZATCA rejects an invoice or the API is down?
A rejected document keeps its hash and counter value, and the next document still chains to it; you fix the cause and issue a new document with its own counter. If ZATCA's servers do not respond, ZATCA's guidelines expect your system to keep retrying at regular intervals and keep a record of each attempt. Simplified invoices still have 24 hours, and a long outage on your side should be notified to ZATCA through the form on its website.
Should we build our own integration or use a provider?
If your invoices come out of an accounting, ERP or POS product, first ask the vendor whether it already handles Phase 2 for you. Building your own makes sense when invoices are generated inside a custom platform you control, such as a booking or SaaS system, and you are prepared to own certificate renewal, monitoring and ZATCA specification updates over time.
Does Bahr AI build ZATCA Phase 2 integrations?
Yes. Bahr AI integrates business systems with ZATCA's Fatoora platform for Phase 2 and has delivered these integrations: onboarding and certificates, XML and signing, clearance and reporting, and monitoring for rejections. Cost follows scope, so we quote after we understand where your invoices are created and which types you issue.