← Guides·ZATCA·6 min read

How to encode a 100%-valid ZATCA Phase-1 invoice QR

The Saudi ZATCA authority requires a QR on every simplified invoice since 2021. This guide explains the right TLV encoding and how CD4CD generates it automatically.

The five required fields

  1. Seller name (Tag 1).
  2. Seller VAT number (Tag 2).
  3. Invoice timestamp ISO 8601 (Tag 3).
  4. Invoice total incl. VAT (Tag 4).
  5. VAT amount (Tag 5).

Encoding: TLV → Base64

Each field is written as Tag (1 byte) | Length (1 byte) | Value (UTF-8). Concatenate the five, then base64-encode.

// Node.js sample
function toTLV(tag, value) {
  const v = Buffer.from(value, 'utf8');
  return Buffer.concat([Buffer.from([tag, v.length]), v]);
}

const tlv = Buffer.concat([
  toTLV(1, 'Aljazera Store'),
  toTLV(2, '300012345600003'),
  toTLV(3, '2026-05-13T15:30:00Z'),
  toTLV(4, '115.00'),
  toTLV(5, '15.00'),
]);
const base64 = tlv.toString('base64');

How CD4CD does it for you

One REST call:

POST /v1/qr
{
  "type": "zatca",
  "data": {
    "sellerName":  "Aljazera Store",
    "vatNumber":   "300012345600003",
    "timestamp":   "2026-05-13T15:30:00Z",
    "totalAmount": "115.00",
    "vatAmount":   "15.00"
  }
}

Validation

Use the official ZATCA Scanner app. If it reads all five fields correctly — the code is compliant.


Ready to apply this?

Open a free account, or log into your dashboard.

Get startedDashboard