---
title: ZATCA E-Invoicing API
slug: zatca-e-invoicing
url: https://apyhub.com/odelyo/service/zatca-e-invoicing
provider: Odelyo
tags: [zatca-e-invoicing, fatoora, zatca-qr-code, saudi-vat, ubl-invoice, e-invoicing]
auth: api_key
version: 1.0.0
service_type: sync
endpoints: 11
atoms: 10-600
mcp: true
---

# ZATCA E-Invoicing API

ZATCA e-invoicing API: onboard a device, build signed UBL 2.1 invoices with the Phase 2 QR code, and report or clear them with Fatoora. Free tier, no card.

## Endpoints

| Method | URL | Description | Atoms |
| --- | --- | --- | --- |
| POST | `https://api.eu.apyhub.com/odelyo/zatca-e-invoicing/onboardings` | What it does Onboards one EGS unit (billing device) with ZATCA in one call. It creates a key pair a… | 600 |
| POST | `https://api.eu.apyhub.com/odelyo/zatca-e-invoicing/csrs` | What it does Creates a secp256k1 key pair and a ZATCA CSR for one EGS unit. Nothing is sent to ZATC… | 10 |
| POST | `https://api.eu.apyhub.com/odelyo/zatca-e-invoicing/compliance-csids` | What it does Sends a CSR and OTP to ZATCA and returns a compliance CSID, used to run compliance che… | 10 |
| POST | `https://api.eu.apyhub.com/odelyo/zatca-e-invoicing/compliance-checks` | What it does Sends one document signed with the compliance CSID to ZATCA's compliance checks and re… | 10 |
| POST | `https://api.eu.apyhub.com/odelyo/zatca-e-invoicing/production-csids` | What it does Exchanges a compliance CSID for a production CSID after the compliance checks pass. Re… | 10 |
| POST | `https://api.eu.apyhub.com/odelyo/zatca-e-invoicing/invoices` | What it does Builds a ZATCA UBL 2.1 invoice, credit note or debit note as XML and calculates the to… | 120 |
| POST | `https://api.eu.apyhub.com/odelyo/zatca-e-invoicing/reports` | What it does Reports a signed simplified (B2C) document to ZATCA. ZATCA requires this within 24 hou… | 120 |
| POST | `https://api.eu.apyhub.com/odelyo/zatca-e-invoicing/clearances` | What it does Clears a signed standard (B2B) document with ZATCA. Share it with the buyer only after… | 120 |
| POST | `https://api.eu.apyhub.com/odelyo/zatca-e-invoicing/qr-codes` | What it does Creates a ZATCA QR payload (TLV, base64) from the five Phase 1 fields. Turn the string… | 10 |
| POST | `https://api.eu.apyhub.com/odelyo/zatca-e-invoicing/qr-codes/decode` | What it does Decodes a ZATCA QR payload and checks that the required fields are present and valid.… | 10 |
| GET | `https://api.eu.apyhub.com/odelyo/zatca-e-invoicing/vat-numbers/:vat_number` | What it does Checks the format of a Saudi VAT number. It does not confirm the number is registered.… | 10 |

## Endpoint reference

### Onboard an EGS unit in one call: key pair, CSR, compliance CSID, all compliance checks, production CSID

`POST https://api.eu.apyhub.com/odelyo/zatca-e-invoicing/onboardings` · 600 atoms · accepts `application/json` · returns `application/json`

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `otp` | body | string | no | 6-digit OTP from the Fatoora portal. Required outside sandbox. Sandbox: 123345. Example: `123345`. |
| `country` | body | string | no | Two-letter country code, uppercase. Example: `SA`. |
| `industry` | body | string | yes | Business activity. Example: `Bakery`. |
| `location` | body | string | yes | Branch address or code. Example: `RRRD2929`. |
| `vat_number` | body | string | yes | Saudi VAT number: 15 digits, starts and ends with 3. Example: `399999999900003`. |
| `common_name` | body | string | yes | Device name. Example: `TST-886431145-399999999900003`. |
| `environment` | body | string | yes | ZATCA environment. Use sandbox for testing. One of: sandbox, simulation, production. Example: `sandbox`. |
| `invoice_type` | body | string | yes | 4 digits of 0/1. 1st = standard (B2B), 2nd = simplified (B2C). 0000 is refused. Example: `1100`. |
| `serial_number` | body | string | yes | Format 1-<maker>\|2-<model>\|3-<serial>. Example: `1-TST\|2-TST\|3-ed22f1d8-e6a2-1118-9b58-d9a8f11e445f`. |
| `organization_name` | body | string | yes | Taxpayer name. Example: `Riyadh Sweet Bakery`. |
| `organization_unit` | body | string | yes | Branch or unit name. Example: `Riyadh Branch`. |

#### Quickstart

Onboard a test device in the sandbox (OTP `123345`).

```bash
curl -X POST "https://api.eu.apyhub.com/odelyo/zatca-e-invoicing/onboardings" \
  -H "apy-token: $APY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"environment":"sandbox","otp":"123345","common_name":"TST-886431145-399999999900003","serial_number":"1-TST|2-TST|3-ed22f1d8-e6a2-1118-9b58-d9a8f11e445f","vat_number":"399999999900003","organization_name":"Riyadh Sweet Bakery","organization_unit":"Riyadh Branch","invoice_type":"1100","location":"RRRD2929","industry":"Bakery","country":"SA"}'
```

#### What you'll get back

Returns a JSON object with `data` (private key, production credentials and the check results) and `meta`.

```json
{
  "data": {
    "completed": true,
    "environment": "sandbox",
    "private_key": "-----BEGIN EC PRIVATE KEY-----\n...\n-----END EC PRIVATE KEY-----\n",
    "credentials": { "certificate": "TUlJRDNqQ0NBNFNn...", "secret": "CkYsEXfV8c1g..." },
    "production_request_id": "30368",
    "compliance_checks": [
      { "document": "standard_invoice", "accepted": true, "status": "CLEARED", "errors": [] },
      { "document": "simplified_invoice", "accepted": true, "status": "REPORTED", "errors": [] }
    ]
  },
  "meta": { "request_id": "req_983c242c4a9a697e", "version": "v1" }
}
```

### Generate a secp256k1 key pair and a ZATCA CSR for one EGS unit (device)

`POST https://api.eu.apyhub.com/odelyo/zatca-e-invoicing/csrs` · 10 atoms · accepts `application/json` · returns `application/json`

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `country` | body | string | no | Two-letter country code, uppercase. Example: `SA`. |
| `industry` | body | string | yes | Business activity. Example: `Bakery`. |
| `location` | body | string | yes | Branch address or code. Example: `RRRD2929`. |
| `vat_number` | body | string | yes | Saudi VAT number: 15 digits, starts and ends with 3. Example: `399999999900003`. |
| `common_name` | body | string | yes | Device name. Example: `TST-886431145-399999999900003`. |
| `environment` | body | string | yes | ZATCA environment. Use sandbox for testing. One of: sandbox, simulation, production. Example: `sandbox`. |
| `invoice_type` | body | string | yes | 4 digits of 0/1. 1st = standard (B2B), 2nd = simplified (B2C). 0000 is refused. Example: `1100`. |
| `serial_number` | body | string | yes | Format 1-<maker>\|2-<model>\|3-<serial>. Example: `1-TST\|2-TST\|3-ed22f1d8-e6a2-1118-9b58-d9a8f11e445f`. |
| `organization_name` | body | string | yes | Taxpayer name. Example: `Riyadh Sweet Bakery`. |
| `organization_unit` | body | string | yes | Branch or unit name. Example: `Riyadh Branch`. |

#### Quickstart

Create a key pair and CSR for a sandbox device.

```bash
curl -X POST "https://api.eu.apyhub.com/odelyo/zatca-e-invoicing/csrs" \
  -H "apy-token: $APY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"environment":"sandbox","common_name":"TST-886431145-399999999900003","serial_number":"1-TST|2-TST|3-ed22f1d8-e6a2-1118-9b58-d9a8f11e445f","vat_number":"399999999900003","organization_name":"Riyadh Sweet Bakery","organization_unit":"Riyadh Branch","invoice_type":"1100","location":"RRRD2929","industry":"Bakery","country":"SA"}'
```

#### What you'll get back

Returns a JSON object with `data` (key and CSR) and `meta`.

```json
{
  "data": {
    "private_key": "-----BEGIN EC PRIVATE KEY-----\n...\n-----END EC PRIVATE KEY-----\n",
    "csr": "-----BEGIN CERTIFICATE REQUEST-----\n...\n-----END CERTIFICATE REQUEST-----\n",
    "csr_base64": "LS0tLS1CRUdJTiBDRVJUSUZJ..."
  },
  "meta": { "request_id": "req_7cad51aacd334626", "version": "v1" }
}
```

### Exchange a CSR and OTP for a compliance CSID

`POST https://api.eu.apyhub.com/odelyo/zatca-e-invoicing/compliance-csids` · 10 atoms · accepts `application/json` · returns `application/json`

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `otp` | body | string | no | 6-digit OTP from the Fatoora portal. Required outside sandbox. Sandbox: 123345. Example: `123345`. |
| `csr_base64` | body | string | yes | csr_base64 from /csrs. Example: `LS0tLS1CRUdJTiBDRVJUSUZJ...`. |
| `environment` | body | string | yes | ZATCA environment. Use sandbox for testing. One of: sandbox, simulation, production. Example: `sandbox`. |

#### Quickstart

Exchange the CSR from `/csrs` for a compliance CSID in the sandbox.

```bash
curl -X POST "https://api.eu.apyhub.com/odelyo/zatca-e-invoicing/compliance-csids" \
  -H "apy-token: $APY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"environment":"sandbox","otp":"123345","csr_base64":"<csr_base64 from /csrs>"}'
```

#### What you'll get back

```json
{
  "data": { "request_id": "1234567890123", "certificate": "TUlJQ1BqQ0NB...", "secret": "GSGMv5oUC7Sx..." },
  "meta": { "request_id": "req_6fb569ce49ba15df", "version": "v1" }
}
```

### Send one document signed with the compliance CSID to ZATCA compliance checks

`POST https://api.eu.apyhub.com/odelyo/zatca-e-invoicing/compliance-checks` · 10 atoms · accepts `application/json` · returns `application/json`

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `invoice.uuid` | body | string (uuid) | yes | uuid from /invoices. Example: `a579e63a-0279-48c9-8fe1-2c37ba7f28be`. |
| `invoice.xml_base64` | body | string | yes | xml_base64 from /invoices. Example: `PD94bWwgdmVyc2lvbj0iMS4w...`. |
| `invoice.invoice_hash` | body | string | yes | invoice_hash from /invoices. Example: `xkCaRQTjpP5Cl8cbqoshIyqh...`. |
| `credentials.secret` | body | string | yes | Secret for the certificate. Example: `CkYsEXfV8c1g...`. |
| `credentials.certificate` | body | string | yes | Certificate as returned by ZATCA (base64). Example: `TUlJRDNqQ0NBNFNn...`. |
| `environment` | body | string | yes | ZATCA environment. Use sandbox for testing. One of: sandbox, simulation, production. Example: `sandbox`. |

#### Quickstart

Check one document signed with the compliance certificate.

```bash
curl -X POST "https://api.eu.apyhub.com/odelyo/zatca-e-invoicing/compliance-checks" \
  -H "apy-token: $APY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"environment":"sandbox","credentials":{"certificate":"<compliance certificate>","secret":"<compliance secret>"},"invoice":{"xml_base64":"<from /invoices>","invoice_hash":"<from /invoices>","uuid":"<from /invoices>"}}'
```

#### What you'll get back

```json
{
  "data": {
    "accepted": true,
    "zatca_http_status": 200,
    "status": "CLEARED",
    "validation": {
      "status": "PASS",
      "info": [{ "code": "XSD_ZATCA_VALID", "category": "XSD validation", "message": "Complied with UBL 2.1 standards in line with ZATCA specifications" }],
      "warnings": [],
      "errors": []
    }
  },
  "meta": { "request_id": "req_…", "version": "v1" }
}
```

### Exchange a compliance CSID for a production CSID

`POST https://api.eu.apyhub.com/odelyo/zatca-e-invoicing/production-csids` · 10 atoms · accepts `application/json` · returns `application/json`

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `credentials.secret` | body | string | yes | Secret for the certificate. Example: `CkYsEXfV8c1g...`. |
| `credentials.certificate` | body | string | yes | Certificate as returned by ZATCA (base64). Example: `TUlJRDNqQ0NBNFNn...`. |
| `environment` | body | string | yes | ZATCA environment. Use sandbox for testing. One of: sandbox, simulation, production. Example: `sandbox`. |
| `compliance_request_id` | body | string | yes | request_id from /compliance-csids. Example: `1234567890123`. |

#### Quickstart

Exchange the compliance CSID for a production CSID.

```bash
curl -X POST "https://api.eu.apyhub.com/odelyo/zatca-e-invoicing/production-csids" \
  -H "apy-token: $APY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"environment":"sandbox","credentials":{"certificate":"<compliance certificate>","secret":"<compliance secret>"},"compliance_request_id":"<request_id from /compliance-csids>"}'
```

#### What you'll get back

```json
{
  "data": { "request_id": "30368", "certificate": "TUlJRDNqQ0NBNFNn...", "secret": "CkYsEXfV8c1g..." },
  "meta": { "request_id": "req_…", "version": "v1" }
}
```

### Build a ZATCA UBL 2.1 invoice, credit or debit note; sign it and add the QR when signing material is sent

`POST https://api.eu.apyhub.com/odelyo/zatca-e-invoicing/invoices` · 120 atoms · accepts `application/json` · returns `application/json`

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | body | string | yes | Your invoice number. Example: `BAKERY-0001`. |
| `note` | body | string | no | Free text note. Example: `Thank you`. |
| `uuid` | body | string (uuid) | no | Invoice UUID. Generated if missing. Example: `3cf5ee18-ee25-44ea-a444-2c37ba7f28be`. |
| `buyer.crn` | body | string | no | Commercial registration number. Example: `1010010000`. |
| `buyer.name` | body | string | yes | Name. Example: `Fatoora Samples LTD`. |
| `buyer.address.city` | body | string | yes | City. Example: `Riyadh`. |
| `buyer.address.street` | body | string | yes | Street. Example: `King Fahd Road`. |
| `buyer.address.country` | body | string | no | Two-letter code, uppercase. Example: `SA`. |
| `buyer.address.district` | body | string | yes | District. Example: `Al Olaya`. |
| `buyer.address.postal_code` | body | string | yes | Exactly 5 digits. Example: `12211`. |
| `buyer.address.building_number` | body | string | yes | Exactly 4 digits. Example: `1234`. |
| `buyer.address.additional_number` | body | string | no | Additional number. Example: `3030`. |
| `buyer.address.additional_street` | body | string | no | Additional street. Example: `Olaya Street`. |
| `buyer.other_id.value` | body | string | yes | ID value. Example: `1010010000`. |
| `buyer.other_id.scheme` | body | string | yes | ID scheme. One of: TIN, CRN, MOM, MLS, 700, SAG, NAT, GCC, IQA, PAS, OTH. Example: `CRN`. |
| `buyer.vat_number` | body | string | yes | 15 digits, starts and ends with 3. Example: `399999999900003`. |
| `lines` | body | array of object | yes | Invoice lines. |
| `lines[].name` | body | string | yes | Item name, 3 characters or more. Example: `Chocolate Cake`. |
| `lines[].quantity` | body | number | yes | Quantity. Example: `1`. |
| `lines[].unit_code` | body | string | no | Unit of measure code. Example: `PCE`. |
| `lines[].unit_price` | body | string | yes | Decimal string, up to 2 decimals. Example: `50.00`. |
| `lines[].vat_percent` | body | number | yes | 15 for S, 0 for Z, E and O. Example: `15`. |
| `lines[].vat_category` | body | string | yes | S standard, Z zero-rated, E exempt, O out of scope. One of: S, Z, E, O. Example: `S`. |
| `lines[].exemption_reason` | body | string | no | Required for Z, E and O. Example: `Financial services mentioned in Article 29 of the VAT Regulations`. |
| `lines[].exemption_reason_code` | body | string | no | Required for Z, E and O. Example: `VATEX-SA-29`. |
| `reason` | body | string | no | Reason for the note. Required for credit and debit notes. Example: `Returned goods`. |
| `seller.crn` | body | string | no | Commercial registration number. Example: `1010010000`. |
| `seller.name` | body | string | yes | Name. Example: `Riyadh Sweet Bakery`. |
| `seller.address.city` | body | string | yes | City. Example: `Riyadh`. |
| `seller.address.street` | body | string | yes | Street. Example: `King Fahd Road`. |
| `seller.address.country` | body | string | no | Two-letter code, uppercase. Example: `SA`. |
| `seller.address.district` | body | string | yes | District. Example: `Al Olaya`. |
| `seller.address.postal_code` | body | string | yes | Exactly 5 digits. Example: `12211`. |
| `seller.address.building_number` | body | string | yes | Exactly 4 digits. Example: `1234`. |
| `seller.address.additional_number` | body | string | no | Additional number. Example: `3030`. |
| `seller.address.additional_street` | body | string | no | Additional street. Example: `Olaya Street`. |
| `seller.other_id.value` | body | string | yes | ID value. Example: `1010010000`. |
| `seller.other_id.scheme` | body | string | yes | ID scheme. One of: TIN, CRN, MOM, MLS, 700, SAG, NAT, GCC, IQA, PAS, OTH. Example: `CRN`. |
| `seller.vat_number` | body | string | yes | 15 digits, starts and ends with 3. Example: `399999999900003`. |
| `counter` | body | integer | yes | Invoice counter for this device. Example: `1`. |
| `signing.certificate` | body | string | yes | Certificate decoded once from base64. Must match the private key. Example: `MIID3jCCA4SgAwIBAgIT...`. |
| `signing.private_key` | body | string | yes | PEM private key. Example: `-----BEGIN EC PRIVATE KEY-----
...
-----END EC PRIVATE KEY-----`. |
| `currency` | body | string | no | Three-letter currency code. Example: `SAR`. |
| `issue_date` | body | string | yes | YYYY-MM-DD. Real date, not in the future. Example: `2026-11-26`. |
| `issue_time` | body | string | yes | HH:MM:SS. Real time. Example: `10:30:00`. |
| `supply_date` | body | string | no | Supply date, YYYY-MM-DD. Example: `2026-11-26`. |
| `invoice_type` | body | string | yes | standard (B2B) or simplified (B2C). One of: standard, simplified. Example: `simplified`. |
| `document_type` | body | string | yes | Document type. One of: invoice, credit_note, debit_note. Example: `invoice`. |
| `previous_hash` | body | string | no | Hash of the previous invoice from this device. Example: `NWZlY2ViNjZmZmM4NmYzOGQ5NTI3ODZjNmQ2OTZjNzljMmRiYzIzOWRkNGU5MWI0NjcyOWQ3M2EyN2Z…`. |
| `billing_reference` | body | string | no | Original invoice number. Required for credit and debit notes. Example: `INV-TST-1`. |
| `payment_means_code` | body | string | no | UN payment means code, 1 to 3 digits. Example: `10`. |

#### Quickstart

Build an unsigned B2C receipt with two lines.

```bash
curl -X POST "https://api.eu.apyhub.com/odelyo/zatca-e-invoicing/invoices" \
  -H "apy-token: $APY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"invoice_type":"simplified","document_type":"invoice","id":"BAKERY-0001","issue_date":"2026-11-26","issue_time":"10:30:00","counter":1,"seller":{"name":"Riyadh Sweet Bakery","vat_number":"399999999900003","address":{"street":"King Fahd Road","building_number":"1234","district":"Al Olaya","city":"Riyadh","postal_code":"12211","country":"SA"}},"lines":[{"name":"Chocolate Cake","quantity":1,"unit_price":"50.00","vat_category":"S","vat_percent":15},{"name":"Coffee","quantity":2,"unit_price":"10.00","vat_category":"S","vat_percent":15}]}'
```

#### What you'll get back

Returns a JSON object with `data` (the XML invoice, its hash and totals) and `meta`. Add `signing` to also get `qr`.

```json
{
  "data": {
    "uuid": "a579e63a-0279-48c9-8fe1-…",
    "invoice_hash": "xkCaRQTjpP5Cl8cbqoshIyqh…",
    "signed": false,
    "xml_base64": "PD94bWwgdmVyc2lvbj0iMS4w…",
    "totals": { "line_total": "70.00", "vat_total": "10.50", "payable": "80.50" }
  },
  "meta": { "request_id": "req_…", "version": "v1" }
}
```

### Report a signed simplified (B2C) document to ZATCA (within 24 hours of issue)

`POST https://api.eu.apyhub.com/odelyo/zatca-e-invoicing/reports` · 120 atoms · accepts `application/json` · returns `application/json`

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `invoice.uuid` | body | string (uuid) | yes | uuid from /invoices. Example: `a579e63a-0279-48c9-8fe1-2c37ba7f28be`. |
| `invoice.xml_base64` | body | string | yes | xml_base64 from /invoices. Example: `PD94bWwgdmVyc2lvbj0iMS4w...`. |
| `invoice.invoice_hash` | body | string | yes | invoice_hash from /invoices. Example: `xkCaRQTjpP5Cl8cbqoshIyqh...`. |
| `credentials.secret` | body | string | yes | Secret for the certificate. Example: `CkYsEXfV8c1g...`. |
| `credentials.certificate` | body | string | yes | Certificate as returned by ZATCA (base64). Example: `TUlJRDNqQ0NBNFNn...`. |
| `environment` | body | string | yes | ZATCA environment. Use sandbox for testing. One of: sandbox, simulation, production. Example: `sandbox`. |

#### Quickstart

Report a signed simplified invoice to the ZATCA sandbox.

```bash
curl -X POST "https://api.eu.apyhub.com/odelyo/zatca-e-invoicing/reports" \
  -H "apy-token: $APY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"environment":"sandbox","credentials":{"certificate":"<production certificate>","secret":"<production secret>"},"invoice":{"xml_base64":"<from /invoices>","invoice_hash":"<from /invoices>","uuid":"<from /invoices>"}}'
```

#### What you'll get back

```json
{
  "data": { "accepted": true, "zatca_http_status": 200, "status": "REPORTED",
            "validation": { "status": "PASS", "info": [], "warnings": [], "errors": [] } },
  "meta": { "request_id": "req_…", "version": "v1" }
}
```

### Clear a signed standard (B2B) document with ZATCA before sharing it with the buyer

`POST https://api.eu.apyhub.com/odelyo/zatca-e-invoicing/clearances` · 120 atoms · accepts `application/json` · returns `application/json`

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `invoice.uuid` | body | string (uuid) | yes | uuid from /invoices. Example: `a579e63a-0279-48c9-8fe1-2c37ba7f28be`. |
| `invoice.xml_base64` | body | string | yes | xml_base64 from /invoices. Example: `PD94bWwgdmVyc2lvbj0iMS4w...`. |
| `invoice.invoice_hash` | body | string | yes | invoice_hash from /invoices. Example: `xkCaRQTjpP5Cl8cbqoshIyqh...`. |
| `credentials.secret` | body | string | yes | Secret for the certificate. Example: `CkYsEXfV8c1g...`. |
| `credentials.certificate` | body | string | yes | Certificate as returned by ZATCA (base64). Example: `TUlJRDNqQ0NBNFNn...`. |
| `environment` | body | string | yes | ZATCA environment. Use sandbox for testing. One of: sandbox, simulation, production. Example: `sandbox`. |

#### Quickstart

Clear a signed standard invoice with the ZATCA sandbox.

```bash
curl -X POST "https://api.eu.apyhub.com/odelyo/zatca-e-invoicing/clearances" \
  -H "apy-token: $APY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"environment":"sandbox","credentials":{"certificate":"<production certificate>","secret":"<production secret>"},"invoice":{"xml_base64":"<from /invoices>","invoice_hash":"<from /invoices>","uuid":"<from /invoices>"}}'
```

#### What you'll get back

```json
{
  "data": { "accepted": true, "zatca_http_status": 200, "status": "CLEARED",
            "validation": { "status": "PASS", "info": [], "warnings": [], "errors": [] } },
  "meta": { "request_id": "req_…", "version": "v1" }
}
```

### Create a ZATCA QR code payload (TLV, base64)

`POST https://api.eu.apyhub.com/odelyo/zatca-e-invoicing/qr-codes` · 10 atoms · accepts `application/json` · returns `application/json`

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `timestamp` | body | string (date-time) | yes | ISO 8601 date-time. Converted to UTC. Example: `2026-11-25T10:00:00Z`. |
| `vat_total` | body | string | yes | Decimal string, up to 2 decimals. Not more than total_with_vat. Example: `150.00`. |
| `vat_number` | body | string | yes | 15 digits, starts and ends with 3. Example: `310122393500003`. |
| `seller_name` | body | string | yes | Seller name, max 255 bytes. Example: `Acme Trading LLC`. |
| `total_with_vat` | body | string | yes | Decimal string, up to 2 decimals. Example: `1150.00`. |

#### Quickstart

Create the QR payload for a receipt.

```bash
curl -X POST "https://api.eu.apyhub.com/odelyo/zatca-e-invoicing/qr-codes" \
  -H "apy-token: $APY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"seller_name":"Acme Trading LLC","vat_number":"310122393500003","timestamp":"2026-11-25T10:00:00Z","total_with_vat":"1150.00","vat_total":"150.00"}'
```

#### What you'll get back

```json
{
  "data": {
    "tlv_base64": "ARBBY21lIFRyYWRpbmcgTExDAg8zMTAxMjIzOTM1MDAwMDMDFDIwMjYtMTEtMjVUMTA6MDA6MDBaBAcxMTUwLjAwBQYxNTAuMDA=",
    "fields": { "seller_name": "Acme Trading LLC", "vat_number": "310122393500003", "timestamp": "2026-11-25T10:00:00Z", "total_with_vat": "1150.00", "vat_total": "150.00" }
  },
  "meta": { "request_id": "req_3fdb4f92b5da98f0", "version": "v1" }
}
```

### Decode and check a ZATCA QR payload

`POST https://api.eu.apyhub.com/odelyo/zatca-e-invoicing/qr-codes/decode` · 10 atoms · accepts `application/json` · returns `application/json`

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `tlv_base64` | body | string | yes | QR payload, base64 or base64url. Example: `AQRBY21lAg8zMTAxMjIzOTM1MDAwMDMDFDIwMjYtMTEtMjVUMTA6MDA6MDBaBAcxMTUwLjAwBQYxNTA…`. |

#### Quickstart

Decode and check a QR payload.

```bash
curl -X POST "https://api.eu.apyhub.com/odelyo/zatca-e-invoicing/qr-codes/decode" \
  -H "apy-token: $APY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"tlv_base64":"AQRBY21lAg8zMTAxMjIzOTM1MDAwMDMDFDIwMjYtMTEtMjVUMTA6MDA6MDBaBAcxMTUwLjAwBQYxNTAuMDA="}'
```

#### What you'll get back

```json
{
  "data": {
    "valid": true,
    "fields": { "seller_name": "Acme", "vat_number": "310122393500003", "timestamp": "2026-11-25T10:00:00Z", "total_with_vat": "1150.00", "vat_total": "150.00" },
    "problems": [],
    "extra_tags": []
  },
  "meta": { "request_id": "req_5a9a1f520da0c84b", "version": "v1" }
}
```

### Check the format of a Saudi VAT number

`GET https://api.eu.apyhub.com/odelyo/zatca-e-invoicing/vat-numbers/:vat_number` · 10 atoms · accepts `application/json` · returns `application/json`

| Parameter | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `vat_number` | path | string | yes | VAT number to check. Example: `310122393500003`. |

#### Quickstart

Check the format of a Saudi VAT number.

```bash
curl -X GET "https://api.eu.apyhub.com/odelyo/zatca-e-invoicing/vat-numbers/:vat_number" \
  -H "apy-token: $APY_TOKEN"
```

#### What you'll get back

```json
{
  "data": { "vat_number": "310122393500003", "valid_format": true, "note": "Format check only. It does not confirm the number is registered." },
  "meta": { "request_id": "req_…", "version": "v1" }
}
```

## About

## What it does
The ZATCA E-Invoicing API handles Saudi Arabia's Phase 2 (Fatoora) e-invoicing in one place. Send invoice data as JSON and get back a signed UBL 2.1 XML invoice, its hash and the Phase 2 QR payload, ready to report or clear with ZATCA.

Start with `/onboardings`. Send your device details and the OTP from the Fatoora portal, and the API returns your private key and production credentials once. Build each document with `/invoices`. Set `invoice_type` to `standard` (B2B) or `simplified` (B2C), and `document_type` to `invoice`, `credit_note` or `debit_note`. Add `signing` to sign it. Then send the result to `/clearances` for standard invoices or `/reports` for simplified ones. Every ZATCA call takes `environment`: `sandbox`, `simulation` or `production`.

The API checks inputs before ZATCA sees them. It refuses impossible or future dates, wrong VAT rates (category `S` must be 15%) and keys that do not match the certificate, with a clear 422 error. Private keys and invoice data are not stored.

Teams use this ZATCA e-invoicing API to add Phase 2 compliance to a POS or ERP, onboard new billing devices, print the Fatoora QR code on receipts, and send credit and debit notes. It returns XML, not PDF.

Pair it with the [Generate QR Code API](https://apyhub.com/apyhub/service/generate-qr-code) to turn the `qr` payload into an image, and the [Convert HTML Content to PDF API](https://apyhub.com/apyhub/service/convert-html-content-to-pdf) to make a printable invoice copy.

## Usage

Base URL: `https://api.eu.apyhub.com` (default region — see
`GET https://apyhub.com/api/public/regions` for the rest).

Authenticate with an ApyHub API key in the `apy-token` header.
Full docs and a live playground: https://apyhub.com/odelyo/service/zatca-e-invoicing
