ZATCA API Integration Guide: Endpoints, Authentication & Implementation

Atif Mehmood March 25, 2026 11 min read Developer Guide

Integrating with ZATCA's e-invoicing API is the core technical requirement of Phase 2 compliance. This guide covers the complete API integration process — from obtaining credentials to submitting invoices in production. If you are a developer building ZATCA integration for Saudi Arabia, this is your technical reference.

API Architecture Overview

ZATCA API integration dashboard

ZATCA's e-invoicing platform exposes a RESTful API with these main operations:

OperationPurposeHTTP Method
Compliance CSIDObtain test certificatePOST
Production CSIDObtain live certificatePOST
Compliance CheckValidate invoice in sandboxPOST
Invoice ClearanceSubmit B2B invoice for approvalPOST
Invoice ReportingReport B2C invoice to ZATCAPOST

Step 1: Generate a Certificate Signing Request (CSR)

Before calling any ZATCA API, you need a digital certificate. The process starts by generating a CSR on your system:

# Generate EC private key openssl ecparam -name secp256k1 -genkey -noout -out ec-private-key.pem # Generate CSR with ZATCA-required fields openssl req -new -sha256 -key ec-private-key.pem -out csr.pem \ -subj "/C=SA/OU=YourOrgUnit/O=YourCompanyName/CN=CSID-XXXXXX"

The CSR must include specific fields that identify your business and solution. ZATCA provides detailed CSR generation instructions in their developer portal documentation.

Step 2: Obtain Compliance CSID

Submit your CSR to ZATCA's compliance endpoint to receive a test certificate:

POST /compliance Content-Type: application/json Accept-Version: V2 OTP: 123456 { "csr": "LS0tLS1CRUdJTi..." // Base64 encoded CSR }

ZATCA responds with a compliance CSID (certificate) and secret that you use for sandbox testing. The OTP is a one-time password provided by ZATCA during onboarding.

Step 3: Authentication

All subsequent API calls use HTTP Basic Authentication. The credentials are constructed by Base64-encoding the CSID and secret:

Authorization: Basic {Base64(csid:secret)} // Example header Authorization: Basic VFVGUF...== Accept-Version: V2 Accept-Language: en Content-Type: application/json

Accept-Version Header

Always include the Accept-Version: V2 header. Omitting this header or using V1 will route your request to deprecated endpoints. ZATCA currently supports V2 for all Phase 2 operations.

Step 4: Submit Invoices for Compliance Testing

Before going live, submit test invoices to the compliance endpoint:

POST /compliance/invoices Authorization: Basic {compliance-csid-credentials} Accept-Version: V2 Content-Type: application/json { "invoiceHash": "NWZlY2ViNjZm...", // SHA-256 hash (Base64) "uuid": "6f4d20e0-6bfe-4a80...", // Must match XML UUID "invoice": "PD94bWwgdmVy..." // Signed XML (Base64) }

Response Structure

{ "invoiceHash": "NWZlY2ViNjZm...", "status": "REPORTED", // or CLEARED, REJECTED "validationResults": { "status": "PASS", // or WARNING, ERROR "infoMessages": [...], "warningMessages": [...], "errorMessages": [ { "type": "ERROR", "code": "BR-KSA-F-06", "category": "KSA", "message": "Invoice line ID must start from 1" } ] } }

For a complete list of error codes and their solutions, see our ZATCA error codes guide.

Step 5: Obtain Production CSID

After all compliance tests pass, exchange your compliance CSID for a production certificate:

POST /production/csids Authorization: Basic {compliance-csid-credentials} Accept-Version: V2 Content-Type: application/json { "compliance_request_id": "1234567890123" }

The production CSID is valid for one year. Your system must renew it before expiry to avoid disruption.

Step 6: Invoice Clearance (B2B)

Standard tax invoices (B2B) are submitted to the clearance endpoint. The invoice must be approved before you deliver it to the buyer:

POST /invoices/clearance/single Authorization: Basic {production-csid-credentials} Accept-Version: V2 Clearance-Status: 1 Content-Type: application/json { "invoiceHash": "...", "uuid": "...", "invoice": "..." }

When the invoice is cleared, ZATCA returns the stamped invoice XML with their own signature. You must use this returned XML (not your original) as the official invoice.

Step 7: Invoice Reporting (B2C)

Simplified tax invoices (B2C) are submitted to the reporting endpoint. You can deliver the invoice to the customer immediately, but must report within 24 hours:

POST /invoices/reporting/single Authorization: Basic {production-csid-credentials} Accept-Version: V2 Content-Type: application/json { "invoiceHash": "...", "uuid": "...", "invoice": "..." }

Handle Failures Gracefully

Your system must handle API timeouts, network errors, and temporary ZATCA outages. Implement a retry queue that stores failed submissions and retries them automatically. For B2C invoices, the 24-hour reporting window provides buffer time. For B2B invoices, failure means you cannot deliver the invoice until clearance succeeds.

Sandbox vs Production Endpoints

EnvironmentBase URLPurpose
Sandboxgw-fatoora.zatca.gov.sa/e-invoicing/developer-portalTesting and development
Simulationgw-fatoora.zatca.gov.sa/e-invoicing/simulationPre-production validation
Productiongw-fatoora.zatca.gov.sa/e-invoicing/coreLive invoices

Best Practices for Integration

  1. Never hardcode credentials. Store CSID certificates and secrets securely, encrypted at rest. Use environment variables or a secrets manager.
  2. Implement exponential backoff. If ZATCA returns a 5xx error, retry with increasing delays (1s, 2s, 4s, 8s) up to a maximum number of attempts.
  3. Log everything. Store the full request and response for every API call. This is essential for debugging rejected invoices and for audit trails.
  4. Monitor certificate expiry. Production CSIDs expire after 1 year. Set up alerts at 30 days and 7 days before expiry.
  5. Validate locally first. Check XML schema compliance and business rules before sending to ZATCA. This reduces API calls and speeds up error resolution.
  6. Handle invoice hash chains carefully. Store the hash of every successfully submitted invoice so the next invoice can reference it correctly.

If building this integration from scratch feels overwhelming, consider using a pre-built solution. A ZATCA-compliant POS like LookPOS handles all API communication, certificate management, XML generation, and error handling automatically.

ZATCA onboarding process in LookPOS

Skip Months of API Integration Work

LookPOS has a fully tested, production-ready ZATCA integration built in. Certificate management, XML signing, API communication, error handling, and retry logic — all handled automatically.

Start Free Trial Talk to Our Dev Team

Frequently Asked Questions

What are the ZATCA API endpoints? +

ZATCA provides endpoints for compliance testing, invoice clearance (B2B), and invoice reporting (B2C). Each environment (sandbox, simulation, production) has its own base URL. All use HTTPS with JSON request/response bodies.

How does ZATCA API authentication work? +

ZATCA uses HTTP Basic Authentication. You Base64-encode your CSID certificate and secret as "csid:secret" and pass it in the Authorization header. Different certificates are used for compliance testing and production.

Can I test without affecting real invoices? +

Yes. ZATCA's sandbox environment allows unlimited test submissions. Sandbox invoices have no legal or tax implications. Use the compliance CSID and sandbox endpoints for all testing. Switch to production CSID and production endpoints only when ready to go live.

What happens if the ZATCA API is down? +

For B2C (reporting), you have 24 hours to report invoices, so temporary outages are manageable — queue and retry. For B2B (clearance), you cannot deliver the invoice until ZATCA approves it. Your system should queue B2B invoices and alert staff when clearance is delayed. A well-designed e-invoicing system handles this automatically.

AM

Atif Mehmood

Founder of LookPOS — Building ZATCA-compliant POS and e-invoicing solutions for businesses across Saudi Arabia since 2018.