Developers

Build on NFatoora

A simple REST API to issue ZATCA-compliant invoices from your own systems — with webhooks, sandbox and code samples.

Productionhttps://api.nfatoora.com/v1 Sandboxhttps://sandbox.api.nfatoora.com/v1
Create a key

Settings → Developers in your dashboard. Start with a sandbox key (nf_test_).

Make a request

Send your first invoice to the sandbox — it never reaches your VAT return.

Go live

Switch to a live key once your device is onboarded with ZATCA.

API overview

Base URL

Environment URL
Production https://api.nfatoora.com/v1
Sandbox https://sandbox.api.nfatoora.com/v1

The sandbox talks to ZATCA's developer environment, so its invoices never affect your VAT returns.

Format

  • All requests and responses are JSON, UTF-8.
  • Dates are ISO 8601 in UTC.
  • Amounts are decimal numbers in SAR.

Pagination

Lists return data, has_more and next_cursor. Send cursor to get the next page and limit (max 100).

Idempotency

Send an Idempotency-Key (any unique value) with POST requests. Retrying with the same key within 24 hours returns the original result instead of creating a new invoice.

Versioning

The current version is v1. We never make breaking changes within a version and announce new versions 6 months in advance.

Authentication

Create a key under Settings → Developers in your dashboard and send it in the Authorization header:

curl https://api.nfatoora.com/v1/account \
  -H "Authorization: Bearer nf_live_xxxxxxxxxxxxxxxx"
Prefix Use
nf_test_ Sandbox
nf_live_ Production

A key can issue invoices on behalf of your business. Never put it in a mobile app or browser code — keep it in server-side environment variables only.

Scopes

Restrict each key to scopes — invoices:write, invoices:read, customers:write, webhooks:write — and optionally to one branch.

Rotating keys

Create a new key, deploy it, then revoke the old one. Each key shows when it was last used.

Errors

The API uses standard HTTP status codes and returns a consistent error object:

{
  "error": {
    "type": "validation_error",
    "code": "invalid_vat_number",
    "message": "vat_number must be 15 digits starting and ending with 3",
    "field": "customer.vat_number",
    "request_id": "req_8Hn2…"
  }
}
Status Type Meaning
400 validation_error Missing or invalid data
401 authentication_error Missing or invalid key
403 permission_error Key lacks the required scope
404 not_found Resource doesn't exist
409 idempotency_error Key reused with a different request
422 zatca_rejected ZATCA rejected the invoice — see zatca.errors
429 rate_limit_error Too many requests
5xx api_error Something went wrong on our side — retry

Include the request_id when you contact support.

Rate limits

Plan Requests per minute
Branches 600
Sandbox 120

Every response includes RateLimit-Limit, RateLimit-Remaining and RateLimit-Reset. Over the limit you get 429 with Retry-After in seconds.

For bulk invoicing, send at most 10 concurrent requests with an Idempotency-Key per invoice.

Webhooks

We send a POST to your URL when these events happen:

Event When
invoice.created An invoice is created
invoice.cleared A standard invoice is cleared
invoice.reported A simplified invoice is reported
invoice.rejected ZATCA rejects an invoice
invoice.paid A payment is recorded
credit_note.created A credit note is issued
csid.expiring A device certificate expires within 30 days

Verifying signatures

Every request carries NFatoora-Signature: t=1763548200,v1=<hex> where v1 = HMAC-SHA256(secret, t + "." + body). Reject requests older than 5 minutes.

$payload = file_get_contents('php://input');
parse_str(str_replace(',', '&', $_SERVER['HTTP_NFATOORA_SIGNATURE']), $sig);
$expected = hash_hmac('sha256', $sig['t'] . '.' . $payload, getenv('NFATOORA_WEBHOOK_SECRET'));
if (!hash_equals($expected, $sig['v1']) || abs(time() - (int) $sig['t']) > 300) {
    http_response_code(400); exit;
}
const crypto = require('crypto');
function verify(rawBody, header, secret) {
  const p = Object.fromEntries(header.split(',').map(x => x.split('=')));
  const expected = crypto.createHmac('sha256', secret).update(p.t + '.' + rawBody).digest('hex');
  return crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(p.v1)) && Math.abs(Date.now() / 1000 - p.t) < 300;
}

Retries

Return a 2xx within 10 seconds. On failure we retry up to 8 times over 24 hours with increasing delays. An event may arrive more than once — use event.id to ignore duplicates.

API reference

Invoices

Create an invoice

POST/v1/invoices

Creates a tax invoice, calculates VAT, generates UBL 2.1 XML with the cryptographic stamp and QR code, then submits it to ZATCA for clearance (standard) or reporting (simplified).

Send an Idempotency-Key header to safely retry without creating duplicates.

Parameters

Field Type Description
type string standard (B2B, cleared) or simplified (B2C, reported). Optional — detected from the customer when omitted.
customer_id string Existing customer ID. Or send customer inline.
lines[] array Line items: description, quantity, unit_price, optional vat_rate (15, 0) and vat_category (S, Z, E, O).
issue_date datetime ISO 8601. Defaults to now.
branch_id string Branch/device that issues the invoice (multi-branch accounts).
notes string Free text printed on the invoice.
send_via array whatsapp, email — deliver to the customer after clearance.

If ZATCA rejects the invoice, the response has status rejected and a zatca.errors list with details.

curl -X POST "https://api.nfatoora.com/v1/invoices" \
  -H "Authorization: Bearer $NFATOORA_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
    "customer_id": "cus_7Hd3",
    "lines": [
        {
            "description": "Split AC installation",
            "quantity": 4,
            "unit_price": 350
        }
    ],
    "send_via": [
        "whatsapp"
    ]
}'
Response
{
    "id": "inv_9Ks2LmQ4",
    "number": "INV-1024",
    "type": "standard",
    "status": "cleared",
    "currency": "SAR",
    "issue_date": "2026-11-19T10:30:00Z",
    "customer": {
        "id": "cus_7Hd3",
        "name": "Elite Contracting Co.",
        "vat_number": "300456789100003"
    },
    "lines": [
        {
            "description": "Split AC installation",
            "quantity": 4,
            "unit_price": 350,
            "vat_rate": 15,
            "line_total": 1400
        }
    ],
    "subtotal": 1400,
    "vat_total": 210,
    "total": 1610,
    "zatca": {
        "uuid": "8e6f2c1a-4b7d-4e1a-9f3c-2d5b7a91c41a",
        "icv": 1024,
        "clearance_status": "CLEARED",
        "qr": "AQ1BbCBBbWFs..."
    },
    "pdf_url": "https://api.nfatoora.com/v1/invoices/inv_9Ks2LmQ4/pdf",
    "created_at": "2026-11-19T10:30:00Z"
}

List invoices

GET/v1/invoices

Returns invoices, newest first. Filter with status, customer_id, from, to; paginate with limit (max 100) and cursor.

curl "https://api.nfatoora.com/v1/invoices?status=cleared&limit=20" \
  -H "Authorization: Bearer $NFATOORA_API_KEY"
Response
{
    "data": [
        {
            "id": "inv_9Ks2LmQ4",
            "number": "INV-1024",
            "type": "standard",
            "status": "cleared",
            "currency": "SAR",
            "issue_date": "2026-11-19T10:30:00Z",
            "customer": {
                "id": "cus_7Hd3",
                "name": "Elite Contracting Co.",
                "vat_number": "300456789100003"
            },
            "lines": [
                {
                    "description": "Split AC installation",
                    "quantity": 4,
                    "unit_price": 350,
                    "vat_rate": 15,
                    "line_total": 1400
                }
            ],
            "subtotal": 1400,
            "vat_total": 210,
            "total": 1610,
            "zatca": {
                "uuid": "8e6f2c1a-4b7d-4e1a-9f3c-2d5b7a91c41a",
                "icv": 1024,
                "clearance_status": "CLEARED",
                "qr": "AQ1BbCBBbWFs..."
            },
            "pdf_url": "https://api.nfatoora.com/v1/invoices/inv_9Ks2LmQ4/pdf",
            "created_at": "2026-11-19T10:30:00Z"
        }
    ],
    "has_more": false,
    "next_cursor": null
}

Retrieve an invoice

GET/v1/invoices/{id}

Returns a single invoice including its ZATCA clearance/reporting status.

curl "https://api.nfatoora.com/v1/invoices/inv_9Ks2LmQ4" \
  -H "Authorization: Bearer $NFATOORA_API_KEY"
Response
{
    "id": "inv_9Ks2LmQ4",
    "number": "INV-1024",
    "type": "standard",
    "status": "cleared",
    "currency": "SAR",
    "issue_date": "2026-11-19T10:30:00Z",
    "customer": {
        "id": "cus_7Hd3",
        "name": "Elite Contracting Co.",
        "vat_number": "300456789100003"
    },
    "lines": [
        {
            "description": "Split AC installation",
            "quantity": 4,
            "unit_price": 350,
            "vat_rate": 15,
            "line_total": 1400
        }
    ],
    "subtotal": 1400,
    "vat_total": 210,
    "total": 1610,
    "zatca": {
        "uuid": "8e6f2c1a-4b7d-4e1a-9f3c-2d5b7a91c41a",
        "icv": 1024,
        "clearance_status": "CLEARED",
        "qr": "AQ1BbCBBbWFs..."
    },
    "pdf_url": "https://api.nfatoora.com/v1/invoices/inv_9Ks2LmQ4/pdf",
    "created_at": "2026-11-19T10:30:00Z"
}

Download PDF

GET/v1/invoices/{id}/pdf

Returns the bilingual PDF/A-3 with the XML embedded. Add ?lang=ar or ?lang=en for the primary language.

curl "https://api.nfatoora.com/v1/invoices/inv_9Ks2LmQ4/pdf?lang=ar" \
  -H "Authorization: Bearer $NFATOORA_API_KEY"
Response
HTTP/1.1 200 OK
Content-Type: application/pdf
Content-Disposition: attachment; filename="INV-1024.pdf"

Download XML

GET/v1/invoices/{id}/xml

Returns the signed UBL 2.1 XML exactly as submitted to ZATCA.

curl "https://api.nfatoora.com/v1/invoices/inv_9Ks2LmQ4/xml" \
  -H "Authorization: Bearer $NFATOORA_API_KEY"
Response
<?xml version="1.0" encoding="UTF-8"?>
<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">
  <cbc:ProfileID>reporting:1.0</cbc:ProfileID>
  <cbc:ID>INV-1024</cbc:ID>
  <cbc:UUID>8e6f2c1a-4b7d-4e1a-9f3c-2d5b7a91c41a</cbc:UUID>
  …
</Invoice>

Create a credit note

POST/v1/invoices/{id}/credit-notes

Creates a credit note linked to the original invoice and submits it to ZATCA. reason is required by ZATCA. Use /debit-notes for a debit note.

curl -X POST "https://api.nfatoora.com/v1/invoices/inv_9Ks2LmQ4/credit-notes" \
  -H "Authorization: Bearer $NFATOORA_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
    "reason": "Returned one AC unit",
    "lines": [
        {
            "description": "Split AC installation",
            "quantity": 1,
            "unit_price": 350
        }
    ]
}'
Response
{
    "id": "crn_3Fa1",
    "number": "CRN-0042",
    "type": "credit_note",
    "status": "cleared",
    "original_invoice": "inv_9Ks2LmQ4",
    "total": -402.5
}

Customers

Create a customer

POST/v1/customers

Adds a customer to your directory. The VAT number format is validated.

Parameters

Field Type Description
name string Legal name. Required.
vat_number string 15-digit VAT number (starts and ends with 3). Required for standard invoices.
cr_number string Commercial registration number.
email string Invoice delivery email.
phone string WhatsApp number in E.164 format.
address object National address: building, street, district, city, postal_code, country.
curl -X POST "https://api.nfatoora.com/v1/customers" \
  -H "Authorization: Bearer $NFATOORA_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
    "name": "Elite Contracting Co.",
    "vat_number": "300456789100003",
    "cr_number": "1010123456",
    "email": "ap@elite.sa",
    "phone": "+966551234567",
    "address": {
        "building": "7235",
        "street": "King Fahd Rd",
        "district": "Al Olaya",
        "city": "Riyadh",
        "postal_code": "12214",
        "country": "SA"
    }
}'
Response
{
    "id": "cus_7Hd3",
    "name": "Elite Contracting Co.",
    "vat_number": "300456789100003",
    "cr_number": "1010123456",
    "email": "ap@elite.sa",
    "phone": "+966551234567",
    "address": {
        "building": "7235",
        "street": "King Fahd Rd",
        "district": "Al Olaya",
        "city": "Riyadh",
        "postal_code": "12214",
        "country": "SA"
    },
    "created_at": "2026-11-01T08:00:00Z"
}

List customers

GET/v1/customers

Lists customers; search with q (name or VAT number).

curl "https://api.nfatoora.com/v1/customers?q=elite&limit=20" \
  -H "Authorization: Bearer $NFATOORA_API_KEY"
Response
{
    "data": [
        {
            "id": "cus_7Hd3",
            "name": "Elite Contracting Co.",
            "vat_number": "300456789100003",
            "cr_number": "1010123456",
            "email": "ap@elite.sa",
            "phone": "+966551234567",
            "address": {
                "building": "7235",
                "street": "King Fahd Rd",
                "district": "Al Olaya",
                "city": "Riyadh",
                "postal_code": "12214",
                "country": "SA"
            },
            "created_at": "2026-11-01T08:00:00Z"
        }
    ],
    "has_more": false,
    "next_cursor": null
}

Retrieve a customer

GET/v1/customers/{id}

Returns a single customer.

curl "https://api.nfatoora.com/v1/customers/cus_7Hd3" \
  -H "Authorization: Bearer $NFATOORA_API_KEY"
Response
{
    "id": "cus_7Hd3",
    "name": "Elite Contracting Co.",
    "vat_number": "300456789100003",
    "cr_number": "1010123456",
    "email": "ap@elite.sa",
    "phone": "+966551234567",
    "address": {
        "building": "7235",
        "street": "King Fahd Rd",
        "district": "Al Olaya",
        "city": "Riyadh",
        "postal_code": "12214",
        "country": "SA"
    },
    "created_at": "2026-11-01T08:00:00Z"
}

Update a customer

PATCH/v1/customers/{id}

Updates only the fields you send. Previously issued invoices are not changed.

curl -X PATCH "https://api.nfatoora.com/v1/customers/cus_7Hd3" \
  -H "Authorization: Bearer $NFATOORA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "email": "finance@elite.sa"
}'
Response
{
    "email": "finance@elite.sa",
    "id": "cus_7Hd3",
    "name": "Elite Contracting Co.",
    "vat_number": "300456789100003",
    "cr_number": "1010123456",
    "phone": "+966551234567",
    "address": {
        "building": "7235",
        "street": "King Fahd Rd",
        "district": "Al Olaya",
        "city": "Riyadh",
        "postal_code": "12214",
        "country": "SA"
    },
    "created_at": "2026-11-01T08:00:00Z"
}

Products

Create a product

POST/v1/products

Saves a product or service with its price and VAT category for invoices and voice messages.

curl -X POST "https://api.nfatoora.com/v1/products" \
  -H "Authorization: Bearer $NFATOORA_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
    "name": "AC maintenance",
    "name_ar": "صيانة مكيف",
    "unit_price": 250,
    "unit": "service",
    "vat_category": "S",
    "vat_rate": 15
}'
Response
{
    "id": "prd_2Qa9",
    "name": "AC maintenance",
    "name_ar": "صيانة مكيف",
    "unit_price": 250,
    "unit": "service",
    "vat_category": "S",
    "vat_rate": 15
}

List products

GET/v1/products

Lists products and services.

curl "https://api.nfatoora.com/v1/products?limit=50" \
  -H "Authorization: Bearer $NFATOORA_API_KEY"
Response
{
    "data": [
        {
            "id": "prd_2Qa9",
            "name": "AC maintenance",
            "name_ar": "صيانة مكيف",
            "unit_price": 250,
            "unit": "service",
            "vat_category": "S",
            "vat_rate": 15
        }
    ],
    "has_more": false,
    "next_cursor": null
}

Webhooks

Create a webhook endpoint

POST/v1/webhook-endpoints

Registers a URL to receive events. The secret is shown once — store it to verify signatures. See the webhooks guide.

curl -X POST "https://api.nfatoora.com/v1/webhook-endpoints" \
  -H "Authorization: Bearer $NFATOORA_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
    "url": "https://example.com/nfatoora/webhook",
    "events": [
        "invoice.cleared",
        "invoice.rejected",
        "invoice.paid"
    ]
}'
Response
{
    "id": "whe_5Tz1",
    "url": "https://example.com/nfatoora/webhook",
    "events": [
        "invoice.cleared",
        "invoice.rejected",
        "invoice.paid"
    ],
    "secret": "whsec_…",
    "active": true
}

List webhook endpoints

GET/v1/webhook-endpoints

Lists registered endpoints (secrets are not returned).

curl "https://api.nfatoora.com/v1/webhook-endpoints" \
  -H "Authorization: Bearer $NFATOORA_API_KEY"
Response
{
    "data": [
        {
            "id": "whe_5Tz1",
            "url": "https://example.com/nfatoora/webhook",
            "events": [
                "invoice.cleared",
                "invoice.rejected",
                "invoice.paid"
            ],
            "active": true
        }
    ],
    "has_more": false,
    "next_cursor": null
}

Delete a webhook endpoint

DELETE/v1/webhook-endpoints/{id}

Stops sending events to this endpoint.

curl -X DELETE "https://api.nfatoora.com/v1/webhook-endpoints/whe_5Tz1" \
  -H "Authorization: Bearer $NFATOORA_API_KEY"
Response
{
    "id": "whe_5Tz1",
    "deleted": true
}

Account

Account & compliance status

GET/v1/account

Returns your business details and the CSID status and expiry for each branch.

curl "https://api.nfatoora.com/v1/account" \
  -H "Authorization: Bearer $NFATOORA_API_KEY"
Response
{
    "business": {
        "name": "Al Amal Cooling Est.",
        "vat_number": "310123456700003"
    },
    "plan": "store",
    "branches": [
        {
            "id": "br_main",
            "name": "Riyadh HQ",
            "csid_status": "active",
            "csid_expires_at": "2027-11-01T00:00:00Z"
        }
    ]
}
Still need help?

Need help integrating? Our engineers reply on WhatsApp and support tickets.

Open a ticket WhatsApp