> ## Documentation Index
> Fetch the complete documentation index at: https://api-doc.fidly.be/llms.txt
> Use this file to discover all available pages before exploring further.

# Create Document

> Issue a document: a sale/purchase invoice, a credit note or a proforma.

Only what identifies the document and what it bills is provided. Everything else is
derived and refused if sent: the number comes from the journal's numbering sequence, the
payment communication is a structured one built from the document itself, and all the
amounts are computed from the lines (`subtotal` = quantity x unit price, then the VAT of
each rate, then the totals). `payment_status` follows from `paid_amount`, and the document
starts `waiting` on the accounting side.

The third party is given by `relation_id` alone: the same identifier space covers business
relations and contacts, so which of the two it is never has to be declared — the response
says it in `relation_type`.

`payment_terms` drives the due date, which is always derived from it and from the issue
date — `due_date` is accepted but ignored. The terms themselves default to the ones set on
the third party, and to `30-df` when it has none — which is always the case for a contact.

The journal must match the document type (a sale invoice goes in a `sales_invoice`
journal, a purchase credit note in a `purchases_credit` one); omit `journal_id` to use the
company's default journal for that category. `purchase_invoice` and `purchase_credit_note`
are self-billing documents and require self-billing to be enabled on the company.

The PDF and, when the type allows it, the Peppol XML are rendered asynchronously: they are
`false` on the freshly created document and become available shortly after — poll
`GET /documents/{id}` to follow it. In sandbox mode the body is validated exactly as in
live mode but nothing is stored, so the returned `id` is not resolvable.

By default **nothing leaves**: the document is written and rendered, and that is all. Add
`?send_peppol=true` to have it put on the network as soon as its files exist — which requires
the `u` permission on top of the `c`, and a type Peppol carries (not a proforma). One flag
per channel, because the channels are independent: mail will join as `send_mail`, and a
document may need one, the other, or both. The send stays asynchronous: the `201` says the
document exists, not that it was delivered.

When the send was asked for but could not be started, the answer is `422 send_failed`
instead of the `201`: the error names the document, which **was** created and numbered.
Do not create it again — retry the send with `POST /documents/{id}/send`.



## OpenAPI

````yaml /openapi.json post /documents
openapi: 3.1.0
info:
  title: Fidly API
  version: 1.0.0
servers:
  - url: https://api.fidly.be
    description: Production
security: []
paths:
  /documents:
    post:
      tags:
        - documents
      summary: Create Document
      description: >-
        Issue a document: a sale/purchase invoice, a credit note or a proforma.


        Only what identifies the document and what it bills is provided.
        Everything else is

        derived and refused if sent: the number comes from the journal's
        numbering sequence, the

        payment communication is a structured one built from the document
        itself, and all the

        amounts are computed from the lines (`subtotal` = quantity x unit price,
        then the VAT of

        each rate, then the totals). `payment_status` follows from
        `paid_amount`, and the document

        starts `waiting` on the accounting side.


        The third party is given by `relation_id` alone: the same identifier
        space covers business

        relations and contacts, so which of the two it is never has to be
        declared — the response

        says it in `relation_type`.


        `payment_terms` drives the due date, which is always derived from it and
        from the issue

        date — `due_date` is accepted but ignored. The terms themselves default
        to the ones set on

        the third party, and to `30-df` when it has none — which is always the
        case for a contact.


        The journal must match the document type (a sale invoice goes in a
        `sales_invoice`

        journal, a purchase credit note in a `purchases_credit` one); omit
        `journal_id` to use the

        company's default journal for that category. `purchase_invoice` and
        `purchase_credit_note`

        are self-billing documents and require self-billing to be enabled on the
        company.


        The PDF and, when the type allows it, the Peppol XML are rendered
        asynchronously: they are

        `false` on the freshly created document and become available shortly
        after — poll

        `GET /documents/{id}` to follow it. In sandbox mode the body is
        validated exactly as in

        live mode but nothing is stored, so the returned `id` is not resolvable.


        By default **nothing leaves**: the document is written and rendered, and
        that is all. Add

        `?send_peppol=true` to have it put on the network as soon as its files
        exist — which requires

        the `u` permission on top of the `c`, and a type Peppol carries (not a
        proforma). One flag

        per channel, because the channels are independent: mail will join as
        `send_mail`, and a

        document may need one, the other, or both. The send stays asynchronous:
        the `201` says the

        document exists, not that it was delivered.


        When the send was asked for but could not be started, the answer is `422
        send_failed`

        instead of the `201`: the error names the document, which **was**
        created and numbered.

        Do not create it again — retry the send with `POST
        /documents/{id}/send`.
      operationId: create_document_documents_post
      parameters:
        - name: send_peppol
          in: query
          required: false
          schema:
            type: boolean
            description: >-
              Put the document on the Peppol network as soon as it is written.
              Requires the `u` permission in addition to `c`, and a type Peppol
              carries. A query parameter, not a body field: it drives what the
              call *does*, it is not part of the document. One flag per channel
              — mail will join as `send_mail`, the two being independent. Omit
              it and nothing leaves.
            default: false
            title: Send Peppol
          description: >-
            Put the document on the Peppol network as soon as it is written.
            Requires the `u` permission in addition to `c`, and a type Peppol
            carries. A query parameter, not a body field: it drives what the
            call *does*, it is not part of the document. One flag per channel —
            mail will join as `send_mail`, the two being independent. Omit it
            and nothing leaves.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/DocumentCreate'
      responses:
        '201':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DocumentOut'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - HTTPBearer: []
components:
  schemas:
    DocumentCreate:
      properties:
        type:
          type: string
          title: Type
          description: >-
            Kind of document to issue. One of ['sale_invoice',
            'sale_credit_note', 'purchase_invoice', 'purchase_credit_note',
            'proforma_invoice'].
        relation_id:
          type: string
          title: Relation Id
          description: >-
            Opaque identifier of the third party the document is issued to. It
            says by itself whether it is a company or a contact — nothing else
            has to be declared.
        relation_type:
          anyOf:
            - type: string
            - type: 'null'
          title: Relation Type
          description: >-
            Ignored: the nature of the third party is read from `relation_id`,
            and the `relation_type` of the response is what it really is.
            Accepted rather than refused so a document that was read can be
            posted back unchanged.
        attachments:
          anyOf:
            - items: {}
              type: array
            - type: 'null'
          title: Attachments
          description: >-
            Ignored: files are attached with `POST /documents/{id}/attachments`,
            never through this body. Accepted so a document that was read can be
            sent back unchanged.
        journal_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Journal Id
          description: >-
            Opaque identifier of the journal to book the document in. Defaults
            to the company's default journal for the category the `type`
            requires.
        delivery_location_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Delivery Location Id
          description: >-
            Opaque identifier of one of the third party's saved delivery
            addresses (`GET /delivery-locations?relation_id=…`), to record where
            the goods go. It must belong to the same third party as the
            document.
        issue_date:
          anyOf:
            - type: string
              format: date
            - type: 'null'
          title: Issue Date
          description: >-
            Date the document is issued. Defaults to today, and cannot be in the
            future — a document dated ahead falls outside the window its number
            is drawn from, and that number would be handed out again to the next
            document.
        due_date:
          anyOf:
            - type: string
              format: date
            - type: 'null'
          title: Due Date
          description: >-
            Ignored: always derived from `payment_terms`, counted from the issue
            date — the terms are the only thing a caller drives. Accepted rather
            than refused so a document that was read can be sent back unchanged.
        payment_terms:
          anyOf:
            - type: string
              pattern: ^\d{1,4}-(df|fm|mf)$
            - type: 'null'
          title: Payment Terms
          description: >-
            Payment terms, as `<days>-<basis>` where days is 0 or more and the
            basis is `df` (from the document's date), `fm` (from the first day
            of the following month) or `mf` (end of the month the delay lands
            in) — for example `30-df`, `0-df` for immediate payment. Defaults to
            the terms set on the third party, and to `30-df` when it has none (a
            contact never has any).
        tax_point_date:
          anyOf:
            - type: string
              format: date
            - type: 'null'
          title: Tax Point Date
          description: >-
            Date the VAT becomes chargeable, when it differs from the issue
            date.
        delivery_date:
          anyOf:
            - type: string
              format: date
            - type: 'null'
          title: Delivery Date
          description: >-
            Date the goods/services were **actually** delivered — a fact, not a
            plan: today or earlier, never a future date.
        period_start:
          anyOf:
            - type: string
              format: date
            - type: 'null'
          title: Period Start
          description: First day of the billed period.
        period_end:
          anyOf:
            - type: string
              format: date
            - type: 'null'
          title: Period End
          description: Last day of the billed period.
        order_number:
          anyOf:
            - type: string
              maxLength: 255
            - type: 'null'
          title: Order Number
          description: Purchase/sales order number referenced by the document.
        despatch_reference:
          anyOf:
            - type: string
              maxLength: 50
            - type: 'null'
          title: Despatch Reference
          description: Reference of the despatch advice (delivery note).
        buyer_reference:
          anyOf:
            - type: string
              maxLength: 50
            - type: 'null'
          title: Buyer Reference
          description: Reference given by the buyer (e.g. a cost centre).
        legal_notice:
          anyOf:
            - type: string
              maxLength: 10000
            - type: 'null'
          title: Legal Notice
          description: >-
            Legal mention printed at the bottom of the document. On a sale
            invoice it defaults to the one configured on the company, as in the
            interface. Independently of it, every exempt VAT group (`exempted`,
            `intra_community`, `export`, `reverse_charge`, `not_subject`)
            carries its own exemption mention on the PDF and in the Peppol XML —
            the company's configured text for that code, else a standard
            wording.
        currency:
          type: string
          maxLength: 20
          title: Currency
          description: >-
            ISO 4217 currency code of every amount, among those Fidly supports
            (`EUR`, `USD`, `GBP`…). Defaults to `EUR`.
          default: EUR
        paid_amount:
          type: number
          maximum: 999999999
          minimum: 0
          title: Paid Amount
          description: >-
            Amount already paid, tax included. Drives `payment_status`; defaults
            to 0 (unpaid).
          default: 0
        lines:
          items:
            $ref: '#/components/schemas/LineIn'
          type: array
          maxItems: 500
          minItems: 1
          title: Lines
          description: The lines to invoice. At least one is required, 500 at most.
        allowance_charges:
          items:
            $ref: '#/components/schemas/AllowanceChargeIn'
          type: array
          maxItems: 50
          title: Allowance Charges
          description: >-
            Discounts and surcharges on the document as a whole, applied after
            the lines and their own. A `rate` is a percentage of the document's
            line total; a fixed `amount` is taken off in full. Each one is
            spread over the VAT rates of the document in proportion to what they
            weigh, because the tax it saves belongs to each of them. That spread
            needs every rate to total a positive amount: if the lines of one
            rate add up to a negative amount, put the discount on the lines
            instead.
      additionalProperties: false
      type: object
      required:
        - type
        - relation_id
        - lines
      title: DocumentCreate
      description: >-
        A document to issue: an invoice, a credit note or a proforma.


        Only what identifies the document and what it bills is provided here.
        Its number, its

        payment communication and every amount are computed from the lines and
        the journal.
    DocumentOut:
      properties:
        id:
          type: string
          title: Id
          description: Opaque unique identifier of the document.
        type:
          type: string
          title: Type
          description: >-
            Document type. One of: `sale_invoice`, `sale_credit_note`,
            `purchase_invoice`, `purchase_credit_note`, `other_document`,
            `unknown`.
        origin:
          type: string
          title: Origin
          description: >-
            Channel the document came in through. One of: `fidly` (generated in
            Fidly), `manual`, `peppol`, `mail`, `odoo`, `billit`, `api` (or
            `unknown`).
        relation_type:
          anyOf:
            - type: string
            - type: 'null'
          title: Relation Type
          description: >-
            Nature of `relation_id`: `company` (a registered business relation)
            or `contact` (an individual contact). `null` when there is no linked
            third party.
        relation_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Relation Id
          description: >-
            Opaque identifier of the third party the document is linked to
            (resolvable via `GET /relations/{id}`). Its nature is given by
            `relation_type`. `null` when the document has no linked third party.
        journal_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Journal Id
          description: >-
            Opaque identifier of the journal the document is booked in
            (resolvable via `GET /journals/{id}`). `null` when the document has
            no linked journal.
        delivery_location_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Delivery Location Id
          description: >-
            Opaque identifier of the saved delivery address the document is
            delivered to (resolvable via `GET /delivery-locations/{id}`). `null`
            when none is set.
        document_number:
          anyOf:
            - type: string
            - type: 'null'
          title: Document Number
          description: The document's own number (e.g. invoice number).
        order_number:
          anyOf:
            - type: string
            - type: 'null'
          title: Order Number
          description: Purchase/sales order number referenced by the document.
        despatch_reference:
          anyOf:
            - type: string
            - type: 'null'
          title: Despatch Reference
          description: >-
            Reference of the despatch advice (delivery note) related to the
            document.
        buyer_reference:
          anyOf:
            - type: string
            - type: 'null'
          title: Buyer Reference
          description: >-
            Reference given by the buyer, to be quoted back on the document
            (e.g. a cost centre).
        issue_date:
          anyOf:
            - type: string
              format: date
            - type: 'null'
          title: Issue Date
          description: Date the document was issued (ISO `YYYY-MM-DD`).
        due_date:
          anyOf:
            - type: string
              format: date
            - type: 'null'
          title: Due Date
          description: Payment due date (ISO `YYYY-MM-DD`).
        payment_terms:
          anyOf:
            - type: string
            - type: 'null'
          title: Payment Terms
          description: >-
            Payment terms the `due_date` follows from, as `<days>-<basis>` (e.g.
            `30-df`). Always `null` on a received document: only documents Fidly
            issues carry them.
        tax_point_date:
          anyOf:
            - type: string
              format: date
            - type: 'null'
          title: Tax Point Date
          description: >-
            Date the VAT becomes chargeable, when it differs from the issue date
            (ISO `YYYY-MM-DD`).
        delivery_date:
          anyOf:
            - type: string
              format: date
            - type: 'null'
          title: Delivery Date
          description: Date the goods/services were actually delivered (ISO `YYYY-MM-DD`).
        period_start:
          anyOf:
            - type: string
              format: date
            - type: 'null'
          title: Period Start
          description: First day of the period the document bills (ISO `YYYY-MM-DD`).
        period_end:
          anyOf:
            - type: string
              format: date
            - type: 'null'
          title: Period End
          description: Last day of the period the document bills (ISO `YYYY-MM-DD`).
        legal_notice:
          anyOf:
            - type: string
            - type: 'null'
          title: Legal Notice
          description: >-
            Legal mention printed at the bottom of the document (e.g. a VAT
            exemption wording). Always `null` on received documents.
        payment_remittance:
          anyOf:
            - type: string
            - type: 'null'
          title: Payment Remittance
          description: >-
            Communication to quote when paying the document. `null` when the
            document carries none.
        is_remittance_structured:
          type: boolean
          title: Is Remittance Structured
          description: >-
            `true` when `payment_remittance` is a structured communication (a
            bank-checked reference such as a Belgian OGM/VCS) rather than free
            text. Always `true` for documents issued by Fidly.
        create_date:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Create Date
          description: >-
            Timestamp the document was created in Fidly (ISO 8601). May be
            `null` on rare legacy rows where it was never set.
        currency:
          anyOf:
            - type: string
            - type: 'null'
          title: Currency
          description: ISO 4217 currency code of all amounts (e.g. `EUR`).
        tax_exclusive_amount:
          anyOf:
            - type: number
            - type: 'null'
          title: Tax Exclusive Amount
          description: Total amount excluding tax.
        tax_amount:
          anyOf:
            - type: number
            - type: 'null'
          title: Tax Amount
          description: Total tax (VAT) amount.
        total_amount:
          anyOf:
            - type: number
            - type: 'null'
          title: Total Amount
          description: Total amount payable, tax included.
        paid_amount:
          anyOf:
            - type: number
            - type: 'null'
          title: Paid Amount
          description: Amount already paid.
        remaining_amount:
          anyOf:
            - type: number
            - type: 'null'
          title: Remaining Amount
          description: Amount still to be paid (`total_amount` minus `paid_amount`).
        payment_status:
          type: string
          title: Payment Status
          description: 'Payment state. One of: `unpaid`, `partial`, `paid` (or `unknown`).'
        accounting_status:
          type: string
          title: Accounting Status
          description: >-
            Accounting workflow state. One of: `waiting`, `accepted`,
            `transfered`, `exported`, `export_error`, `imported`, `validated`,
            `hidden`, `exporting`, `posting`, `posting_error`, `deleted` (or
            `unknown`).
        pdf_available:
          type: boolean
          title: Pdf Available
          description: >-
            `true` if a PDF is stored for this document (retrievable via the
            file endpoint).
        xml_available:
          type: boolean
          title: Xml Available
          description: >-
            `true` if a structured XML version (e.g. Peppol/UBL) is stored for
            this document.
        peppol_status:
          anyOf:
            - type: string
            - type: 'null'
          title: Peppol Status
          description: >-
            Peppol send state of an issued document. One of: `not_sent`,
            `sending`, `sent` (delivered to the network), `accepted`
            (acknowledged by the recipient), `rejected` (refused by the
            recipient), `failed` (or `unknown`). `rejected` and `failed` can be
            sent again. Always `null` on a received document.
        mail_status:
          anyOf:
            - type: string
            - type: 'null'
          title: Mail Status
          description: >-
            E-mail send state of an issued document. One of: `not_sent`, `sent`,
            `failed` (or `unknown`). Always `null` on a received document.
        attachments:
          items:
            $ref: '#/components/schemas/AttachmentOut'
          type: array
          title: Attachments
          description: >-
            Files attached to the document, in the order they were added. Attach
            one with `POST /documents/{id}/attachments`; the API offers no way
            to remove one. A received document never carries any.
        allowance_charges:
          items:
            $ref: '#/components/schemas/AllowanceChargeOut'
          type: array
          title: Allowance Charges
          description: >-
            Discounts/surcharges applied to the document as a whole, after the
            lines and their own. `tax_exclusive_amount` is already net of them.
        lines:
          items:
            $ref: '#/components/schemas/LineOut'
          type: array
          title: Lines
          description: >-
            Detailed lines of the document (invoiced items/services). Empty when
            none are stored.
      additionalProperties: true
      type: object
      required:
        - id
        - type
        - origin
        - document_number
        - order_number
        - despatch_reference
        - buyer_reference
        - issue_date
        - due_date
        - tax_point_date
        - delivery_date
        - period_start
        - period_end
        - payment_remittance
        - is_remittance_structured
        - create_date
        - currency
        - tax_exclusive_amount
        - tax_amount
        - total_amount
        - paid_amount
        - remaining_amount
        - payment_status
        - accounting_status
        - pdf_available
        - xml_available
      title: DocumentOut
      description: >-
        A document of the company: an invoice/credit note it issued or a
        document it

        received (purchase invoice, credit note, other). The source table is
        hidden — the

        client sees a single unified document identified by an opaque `id`.


        Monetary amounts are decimal numbers in the document's `currency`. They
        may be `null`

        when the document could not be parsed automatically, or for
        `other_document` types

        that have no financial breakdown.


        Both sources are normalised to this shape by the repository adapters;
        the validators

        below map the internal codes to their public values.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    LineIn:
      properties:
        item_name:
          type: string
          maxLength: 255
          minLength: 1
          title: Item Name
          description: Name of the item/service.
        quantity:
          type: number
          maximum: 999999999
          minimum: -999999999
          title: Quantity
          description: >-
            Quantity of the item. May be negative: that is how a line subtracts,
            the unit price never being negative.
        unit_price:
          type: number
          maximum: 999999999
          minimum: 0
          title: Unit Price
          description: >-
            Price for one unit, before tax. Never negative (Peppol BR-27): a
            line that subtracts is written with a negative `quantity`.
        vat_code:
          type: string
          title: Vat Code
          description: >-
            VAT regime of the line, one of ['standard', 'exempted',
            'zero_rated', 'reverse_charge', 'intra_community', 'export',
            'not_subject'] (the UNCL5305 categories by name): `standard` is the
            only rated one, the others are 0% regimes — `exempted` (art. 44),
            `zero_rated`, `reverse_charge` (cocontractant), `intra_community`
            (EU supply), `export` (outside the EU), `not_subject`.
            Case-insensitive. `standard`, `exempted`, `zero_rated` and
            `reverse_charge` may be mixed on one document; ['intra_community',
            'export', 'not_subject'] are exclusive — a document carrying one of
            them must carry it on every line.
        vat_rate:
          anyOf:
            - type: number
              maximum: 100
              minimum: 0
            - type: 'null'
          title: Vat Rate
          description: >-
            VAT rate applied to the line, in percent. Required above 0 with the
            `standard` code (6, 12 or 21 in Belgium); refused with
            `not_subject`, which carries no rate at all (Peppol BR-O-05); every
            other code is a 0% regime, so it may be omitted — sent along, it
            must be 0.
        sequence:
          anyOf:
            - type: integer
            - type: 'null'
          title: Sequence
          description: >-
            Ignored: lines are numbered by their position in `lines`, starting
            at 1. Accepted rather than refused so a line copied from a document
            that was read still passes.
        subtotal:
          anyOf:
            - type: number
            - type: 'null'
          title: Subtotal
          description: >-
            Ignored: derived from `quantity`, `unit_price`, `vat_rate` and the
            line's allowances/charges. Accepted so a line read from a document
            can be sent back unchanged.
        total:
          anyOf:
            - type: number
            - type: 'null'
          title: Total
          description: >-
            Ignored: derived from `quantity`, `unit_price`, `vat_rate` and the
            line's allowances/charges. Accepted so a line read from a document
            can be sent back unchanged.
        tax_amount:
          anyOf:
            - type: number
            - type: 'null'
          title: Tax Amount
          description: >-
            Ignored: derived from `quantity`, `unit_price`, `vat_rate` and the
            line's allowances/charges. Accepted so a line read from a document
            can be sent back unchanged.
        item_description:
          anyOf:
            - type: string
              maxLength: 1000
            - type: 'null'
          title: Item Description
          description: Longer description of the item/service.
        section_name:
          anyOf:
            - type: string
              maxLength: 255
            - type: 'null'
          title: Section Name
          description: Title of the section this line belongs to, if any.
        unit_code:
          type: string
          maxLength: 20
          title: Unit Code
          description: >-
            Unit of measure the quantity is expressed in: a UN/ECE
            Recommendation 20 code among those Fidly supports (`C62`, `HUR`,
            `KGM`, `LTR`…). Defaults to `C62` (one unit).
          default: C62
        item_properties:
          anyOf:
            - additionalProperties:
                type: string
              type: object
            - type: 'null'
          title: Item Properties
          description: >-
            Free item properties, as a flat object of string values (no
            nesting).
        item_identification:
          anyOf:
            - type: string
              maxLength: 255
            - type: 'null'
          title: Item Identification
          description: Standard item identifier (e.g. GTIN).
        product_code:
          anyOf:
            - type: string
              maxLength: 255
            - type: 'null'
          title: Product Code
          description: Seller's own product code.
        allowance_charges:
          items:
            $ref: '#/components/schemas/LineAllowanceChargeIn'
          type: array
          title: Allowance Charges
          description: >-
            Discounts and surcharges applied to this line, before tax. The line
            total is `subtotal + charges - allowances`, and the VAT is computed
            on it. Unlike a document-level one, naming the reason is optional:
            without `code` nor `reason`, the catch-all code of the kind is
            applied (`95` for an allowance, `ZZZ` for a charge) and returned in
            the response.
      additionalProperties: false
      type: object
      required:
        - item_name
        - quantity
        - unit_price
        - vat_code
      title: LineIn
      description: >-
        A line to invoice. `subtotal`, `total` and `tax_amount` are derived from
        `quantity`,

        `unit_price`, `vat_rate` and the line's allowances/charges — they are
        outputs, not inputs,

        and are ignored if sent.
    AllowanceChargeIn:
      properties:
        type:
          type: string
          title: Type
          description: >-
            `allowance` (discount) or `charge` (surcharge). One of ['allowance',
            'charge'].
        amount:
          anyOf:
            - type: number
              maximum: 999999999
              exclusiveMinimum: 0
            - type: 'null'
          title: Amount
          description: Fixed amount, before tax. Ignored when `rate` is also given.
        rate:
          anyOf:
            - type: number
              maximum: 100
              exclusiveMinimum: 0
            - type: 'null'
          title: Rate
          description: >-
            Percentage from which the amount is computed: of the line's subtotal
            on a line, of the document's line total on the document.
        code:
          anyOf:
            - type: string
              maxLength: 25
            - type: 'null'
          title: Code
          description: >-
            Reason code — UNCL5189 for an allowance (`95` = discount), UNCL7161
            for a charge (`AAA` = telecommunication). Required unless `reason`
            is given.
        reason:
          anyOf:
            - type: string
              maxLength: 255
            - type: 'null'
          title: Reason
          description: Free-text reason. Required unless `code` is given.
      additionalProperties: false
      type: object
      required:
        - type
      title: AllowanceChargeIn
      description: >-
        A discount or a surcharge, on a line or on the document as a whole.


        Either a fixed `amount` or a `rate` of what it applies to — the line's
        subtotal on a

        line, the document's line total on the document. Both may be sent — that
        is what reading

        a document gives back, since the stored percentage is returned next to
        the amount it

        produced — and `rate` then wins, because that is how the rest of the
        platform resolves

        the pair (the amount is recomputed from the base and the percentage).
    AttachmentOut:
      properties:
        filename:
          anyOf:
            - type: string
            - type: 'null'
          title: Filename
          description: Name of the attached file.
        mimetype:
          anyOf:
            - type: string
            - type: 'null'
          title: Mimetype
          description: Media type of the attached file.
      type: object
      title: AttachmentOut
      description: >-
        A file attached to a document. Where it is stored (bucket and key) stays
        internal.
    AllowanceChargeOut:
      properties:
        code:
          anyOf:
            - type: string
            - type: 'null'
          title: Code
          description: Reason code for the allowance/charge.
        type:
          anyOf:
            - type: string
            - type: 'null'
          title: Type
          description: '`allowance` (discount) or `charge` (surcharge).'
        amount:
          anyOf:
            - type: number
            - type: 'null'
          title: Amount
          description: Monetary amount of the allowance/charge.
        reason:
          anyOf:
            - type: string
            - type: 'null'
          title: Reason
          description: Free-text reason.
        rate:
          anyOf:
            - type: number
            - type: 'null'
          title: Rate
          description: Percentage rate, when expressed as a percentage.
      type: object
      title: AllowanceChargeOut
      description: A discount (allowance) or surcharge (charge) applied to a document line.
    LineOut:
      properties:
        sequence:
          anyOf:
            - type: integer
            - type: 'null'
          title: Sequence
          description: Position of the line within the document.
        quantity:
          anyOf:
            - type: number
            - type: 'null'
          title: Quantity
          description: Quantity of the item.
        vat_rate:
          anyOf:
            - type: number
            - type: 'null'
          title: Vat Rate
          description: >-
            VAT rate applied to the line, in percent. Always `null` on a
            `not_subject` line: outside the scope of VAT there is no rate at all
            (Peppol BR-O-05).
        item_name:
          anyOf:
            - type: string
            - type: 'null'
          title: Item Name
          description: Name of the item/service.
        item_description:
          anyOf:
            - type: string
            - type: 'null'
          title: Item Description
          description: Longer description of the item/service.
        unit_price:
          anyOf:
            - type: number
            - type: 'null'
          title: Unit Price
          description: Price for one unit, before tax.
        unit_code:
          anyOf:
            - type: string
            - type: 'null'
          title: Unit Code
          description: Unit of measure code (e.g. `C62` for unit).
        vat_code:
          anyOf:
            - type: string
            - type: 'null'
          title: Vat Code
          description: >-
            VAT regime of the line: `standard`, `exempted`, `zero_rated`,
            `reverse_charge`, `intra_community`, `export` or `not_subject`.
            Legacy documents may carry the reserved `transferred_vat`,
            `canary_islands` or `ceuta_melilla`.
        subtotal:
          anyOf:
            - type: number
            - type: 'null'
          title: Subtotal
          description: Line amount before discounts, excluding tax.
        total:
          anyOf:
            - type: number
            - type: 'null'
          title: Total
          description: Line amount after discounts, excluding tax.
        tax_amount:
          anyOf:
            - type: number
            - type: 'null'
          title: Tax Amount
          description: Tax (VAT) amount of the line.
        section_name:
          anyOf:
            - type: string
            - type: 'null'
          title: Section Name
          description: Title of the section this line belongs to, if any.
        item_properties:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Item Properties
          description: Free key/value item properties, kept as-is.
        item_identification:
          anyOf:
            - type: string
            - type: 'null'
          title: Item Identification
          description: Standard item identifier (e.g. GTIN).
        product_code:
          anyOf:
            - type: string
            - type: 'null'
          title: Product Code
          description: Seller's own product code.
        allowance_charges:
          items:
            $ref: '#/components/schemas/AllowanceChargeOut'
          type: array
          title: Allowance Charges
          description: Discounts/surcharges applied to this line.
      type: object
      title: LineOut
      description: A single line of a document (one invoiced item/service).
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
    LineAllowanceChargeIn:
      properties:
        type:
          type: string
          title: Type
          description: >-
            `allowance` (discount) or `charge` (surcharge). One of ['allowance',
            'charge'].
        amount:
          anyOf:
            - type: number
              maximum: 999999999
              exclusiveMinimum: 0
            - type: 'null'
          title: Amount
          description: Fixed amount, before tax. Ignored when `rate` is also given.
        rate:
          anyOf:
            - type: number
              maximum: 100
              exclusiveMinimum: 0
            - type: 'null'
          title: Rate
          description: >-
            Percentage from which the amount is computed: of the line's subtotal
            on a line, of the document's line total on the document.
        code:
          anyOf:
            - type: string
              maxLength: 25
            - type: 'null'
          title: Code
          description: >-
            Reason code — UNCL5189 for an allowance (`95` = discount), UNCL7161
            for a charge (`AAA` = telecommunication). Required unless `reason`
            is given.
        reason:
          anyOf:
            - type: string
              maxLength: 255
            - type: 'null'
          title: Reason
          description: Free-text reason. Required unless `code` is given.
      additionalProperties: false
      type: object
      required:
        - type
      title: LineAllowanceChargeIn
      description: >-
        A line allowance/charge, where naming the reason is optional.


        Peppol asks for a reason or a reason code here too (BR-CO-23/24), and
        nothing downstream

        supplies one: `_allowance_charge_to_details` stores what it is given,
        and

        `FidlyCreateInvoice` hands it straight to `LineAllowanceCharge`, which
        raises when both are

        empty — after the 201. So the code is filled in here rather than
        demanded, and the response

        reads it back, so the caller sees what was assumed.
  securitySchemes:
    HTTPBearer:
      type: http
      scheme: bearer

````