{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://invoiceko.com/schema/invoice.json",
  "title": "InvoiceKo prefill payload",
  "description": "Invoice data accepted by InvoiceKo prefill links (https://invoiceko.com/new?d=<base64url of this JSON>). All fields are optional; missing fields get sensible defaults. Snake_case aliases (tax_rate, issue_date, due_date, tax_id, discount_type, discount_value, tax_label) are also accepted.",
  "type": "object",
  "additionalProperties": true,
  "properties": {
    "from": { "$ref": "#/$defs/party", "description": "The issuer of the invoice." },
    "to": { "$ref": "#/$defs/party", "description": "The client being billed." },
    "number": { "type": "string", "maxLength": 60, "examples": ["INV-0042"] },
    "issueDate": { "type": "string", "pattern": "^\\d{4}-\\d{2}-\\d{2}$" },
    "dueDate": { "type": "string", "pattern": "^\\d{4}-\\d{2}-\\d{2}$" },
    "currency": {
      "type": "string",
      "enum": ["USD", "EUR", "GBP", "INR", "AUD", "CAD", "SGD", "AED", "JPY", "CNY", "CHF", "SEK", "NOK", "DKK", "NZD", "ZAR", "BRL", "MXN", "IDR", "PHP", "MYR", "THB", "SAR", "NGN", "KES"]
    },
    "items": {
      "type": "array",
      "maxItems": 100,
      "items": {
        "type": "object",
        "properties": {
          "description": { "type": "string", "maxLength": 500 },
          "quantity": { "type": "number", "minimum": 0, "default": 1 },
          "rate": { "type": "number", "minimum": 0, "description": "Unit price. Line amount is computed as quantity × rate." }
        }
      }
    },
    "taxLabel": { "type": "string", "enum": ["Tax", "GST", "VAT", "Sales Tax"] },
    "taxRate": { "type": "number", "minimum": 0, "maximum": 100, "description": "Percent, applied to the post-discount subtotal." },
    "discountType": { "type": "string", "enum": ["percent", "flat"] },
    "discountValue": { "type": "number", "minimum": 0 },
    "shipping": { "type": "number", "minimum": 0, "description": "Flat amount added after tax." },
    "notes": { "type": "string", "maxLength": 1000 },
    "terms": { "type": "string", "maxLength": 1000 }
  },
  "$defs": {
    "party": {
      "type": "object",
      "properties": {
        "name": { "type": "string", "maxLength": 200 },
        "address": { "type": "string", "maxLength": 500 },
        "email": { "type": "string", "maxLength": 200 },
        "phone": { "type": "string", "maxLength": 50 },
        "taxId": { "type": "string", "maxLength": 100, "description": "Tax ID / GSTIN / VAT number." }
      }
    }
  }
}
