{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/lumabill-ch/json-schema/lumabill-ch-invoice-write-schema.json",
  "title": "InvoiceWrite",
  "x-generated": "2026-11-17",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/lumabill-ch-openapi.yaml#/components/schemas/InvoiceWrite",
  "type": "object",
  "required": [
    "lines"
  ],
  "properties": {
    "invoice_number": {
      "type": [
        "string",
        "null"
      ],
      "description": "Explicit number (imports, own numbering schemes), stored as given also on a draft; 409 DUPLICATE_INVOICE_NUMBER when another document of the same type in the profile already uses it. If omitted, a draft stays unnumbered and the next number from the profile prefix + counter (e.g. `IV-010`) is assigned when the document is issued (status leaves draft, or it is emailed). null clears the number of a never-issued draft; an issued document keeps its number.\n"
    },
    "client_id": {
      "type": "string",
      "format": "uuid",
      "description": "UUID of an existing client. The API fetches the client data and snapshots it on the invoice. Returns `404` if not found.\n"
    },
    "status": {
      "type": "string",
      "enum": [
        "draft",
        "sent"
      ],
      "default": "draft"
    },
    "issue_date": {
      "type": "string",
      "format": "date",
      "description": "Defaults to today if omitted."
    },
    "due_date": {
      "type": "string",
      "format": "date",
      "description": "Defaults to `issue_date` + profile payment deadline days (default 30) if omitted.\n"
    },
    "currency": {
      "allOf": [
        {
          "$ref": "#/$defs/Currency"
        }
      ],
      "description": "Defaults to profile default currency (usually `CHF`)."
    },
    "exchangeRate": {
      "type": [
        "number",
        "null"
      ],
      "format": "double",
      "description": "Foreign-currency invoice only: CHF per 1 unit of `currency`, stored as a manual rate (MWSTV 45 Abs. 3bis). Omit to use the ESTV/BAZG rate of the invoice date. Taken while the invoice is a draft or by the write that issues it; an issued invoice keeps its rate. Issuing a foreign-currency invoice without any rate (e.g. dated in a Monatsmittel month that has not started) is refused with 400 FX_RATE_UNAVAILABLE; when ESTV/BAZG cannot be reached and no rate is cached the write answers 400 FX_RATE_SOURCE_UNAVAILABLE (retry later, it is not a missing rate); 400 INVALID_EXCHANGE_RATE when not a positive number, 400 EXCHANGE_RATE_IMPLAUSIBLE when outside 0.5x to 2x of the ESTV/BAZG rate of the date (0.0001 to 100 without one; the body carries `officialRate`, `min`, `max`). `null` is the same as omitting it (unlike the expense and revenue update, it does not drop a stored manual rate).\n"
    },
    "lines": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/InvoiceLine"
      }
    },
    "notes": {
      "type": [
        "string",
        "null"
      ]
    },
    "payment_terms": {
      "type": [
        "string",
        "null"
      ]
    }
  },
  "$defs": {
    "Currency": {
      "type": "string",
      "description": "ISO 4217 code of a currency the API converts (ESTV/BAZG rates). The same list applies to every currency field of the API.\n",
      "enum": [
        "CHF",
        "EUR",
        "USD",
        "GBP",
        "JPY",
        "CAD",
        "AUD",
        "SEK",
        "NOK",
        "DKK",
        "HUF"
      ]
    },
    "InvoiceLine": {
      "type": "object",
      "required": [
        "description",
        "quantity",
        "price"
      ],
      "properties": {
        "catalog_item_id": {
          "type": "string",
          "format": "uuid",
          "description": "Takes the line from a catalog item of the profile: title, description (as `details`), price and unit, plus tax rate, discount and VAT code where the document shows those columns. Fields sent with it win; `description` and `price` may then be omitted. `404 CATALOG_ITEM_NOT_FOUND` if unknown.\n"
        },
        "description": {
          "type": "string"
        },
        "details": {
          "type": [
            "string",
            "null"
          ],
          "description": "Detail text printed under the description."
        },
        "quantity": {
          "type": "number",
          "format": "double"
        },
        "price": {
          "type": "number",
          "format": "double"
        },
        "vat_rate": {
          "type": [
            "number",
            "null"
          ],
          "format": "double",
          "description": "VAT rate as a percentage (e.g. 8.1 for 8.1 %). If omitted, the profile's default tax rate is used.\n"
        }
      }
    }
  }
}