Complete API Guide for Phase 2 E-Invoicing Compliance
Last updated: March 30, 2026
The **Fatoora portal** is ZATCA's (Zakat, Tax and Customs Authority) electronic invoicing platform. All taxpayers in Saudi Arabia must integrate their systems with Fatoora APIs for Phase 2 compliance. This comprehensive guide covers everything from authentication to production deployment.
| Endpoint Name | Endpoint URL | Method | Description |
|---|---|---|---|
| Clearance (B2B) | https://api.fatoora.zatca.gov.sa/api/v1/invoice/clearance | POST | Real-time validation for B2B invoices |
| Reporting (B2C) | https://api.fatoora.zatca.gov.sa/api/v1/invoice/reporting | POST | 24-hour submission for B2C invoices |
| CSR Generation | https://api.fatoora.zatca.gov.sa/api/v1/csr | POST | Generate Certificate Signing Request |
| Compliance Check | https://sandbox.fatoora.zatca.gov.sa/api/v1/compliance | POST | Validate XML before submission |
Fatoora APIs use OAuth 2.0 with client credentials flow. After CSD certificate installation, you must obtain credentials from ZATCA portal:
Token endpoint: https://api.fatoora.zatca.gov.sa/oauth2/token
Here is a complete PHP cURL example for submitting an invoice to the Clearance endpoint:
Invoice accepted by ZATCA. You can share it with buyer.
Action: Proceed with delivery
Invoice failed validation. Check XML structure and fields.
Action: Correct and resubmit new invoice
Invoice accepted for reporting (no real-time validation).
Action: No further action needed
Invoice under review. Wait for final status.
Action: Implement webhook to receive update
| HTTP Code | Meaning | Solution |
|---|---|---|
| 200 | Success - Invoice processed correctly | Continue normal flow |
| 400 | Bad Request - Invalid XML format or missing mandatory fields | Validate XML against UBL 2.1 schema |
| 401 | Unauthorized - Authentication failed | Check access_token validity and regenerate if expired |
| 403 | Forbidden - CSD certificate expired or invalid | Renew CSD certificate immediately |
| 429 | Rate Limit Exceeded - Too many requests | Implement exponential backoff and reduce request rate |
| 500 | Internal Server Error - ZATCA server issue | Retry with exponential backoff (max 3 attempts) |
| 503 | Service Unavailable - Maintenance or overload | Wait and retry after 5-10 minutes |
Always test your integration in the ZATCA Sandbox before going live:
๐ https://sandbox.fatoora.zatca.gov.sa
A: Clearance endpoint: 2-5 seconds (synchronous). Reporting endpoint: Response within seconds (asynchronous), but invoice status may update later via webhook or status check endpoint.
A: Standard limit is 10 requests per second. For higher volumes (enterprise), contact ZATCA support to request increased limits. Implement queue system for bulk submissions.
A: Yes, access tokens typically expire after 1 hour. Implement auto-refresh logic to obtain new token before expiry. Do not request new token for every request.
A: You cannot edit a rejected invoice. You must correct the issue in your system and submit a brand new invoice with a new invoice number. Rejected invoices cannot be resubmitted.
A: ZATCA Sandbox provides test CSD certificates for free. You can generate them directly from the sandbox portal without purchasing from commercial providers.
A: Clearance is synchronous - you wait for immediate response. Reporting is asynchronous - you submit and receive acknowledgement, but final status comes later via webhook.
A: No, static IP is not required. However, ensure your server's outbound IP is not blocked by ZATCA firewall. Use reliable hosting provider.
A: ZATCA accepts HTTPS endpoints only. URL must be publicly accessible. Use POST method to receive JSON payloads with invoice status updates.