openapi: 3.1.0
info:
  title: Otazio API
  version: 0.1.0
  description: |-
    The otazio REST API: the same surface the web app, the MCP server and your
    own integrations use. Every action in the app is an
    endpoint here.

    ## Getting started

    ### Base URL

    Everything about one business lives under
    `{server}/v1/businesses/{businessID}/`. The server is `https://api.otazio.com`. Sign-in and the list of your businesses are under
    `/bff/`. Customer-facing pages (no sign-in) are under `/p/`.

    Each business is a separate book with its own database. A business id from
    `GET /bff/me` is the only thing you need to address it.

    ### Authentication

    Today the API uses the web app's session:

    1. Sign in through `GET /bff/login` (an OpenID Connect redirect to the
    identity provider). The server keeps the tokens and sets two cookies:
    `otazio_session` (HttpOnly) and `otazio_csrf` (readable).
    2. Send both cookies on every request.
    3. On every request that changes something (`POST`, `PATCH`), also send the
    header `X-CSRF-Token` with the value of the `otazio_csrf` cookie. Missing
    or wrong, the request fails with `403 csrf-failed`.
    4. `GET /bff/me` returns who you are and the businesses you can open.

    You have the same permissions through the API as in the app: viewers can
    read, owners and editors can write (`403 permission-denied` otherwise).

    API keys for server-to-server use are planned: opaque
    keys, each its own principal that can be granted narrowly and revoked on
    its own, used instead of the cookies. Until then, integrations sign in as a
    user.

    ### Ids, dates and times

    Record ids are UUID strings. Dates are `YYYY-MM-DD` and are accounting dates
    (the date on the document, which decides the period). Timestamps such as
    `created_at` are RFC 3339 in UTC with milliseconds.

    ### Money

    Money is a decimal string with exactly two places: `"125.00"`, `"-10.50"`.
    Never convert it to a floating-point number. On input a JSON number such as
    `125` or `125.5` is also accepted, but more than two decimal places is
    rejected. Quantities and percentages (`quantity`, `tax_rate`,
    `sales_tax_rate`, `margin_percent`) are decimal strings with up to four
    places, trailing zeros trimmed: `"1.5"`, `"8.25"`.

    ### Idempotency

    Every `POST` under `/v1/businesses/{businessID}/` accepts an
    `Idempotency-Key` header (at most 200 characters). The first response is
    stored and replayed for a retry with the same key and the same body, with
    the header `Idempotent-Replayed: true`. The same key with a different body
    is a `422 validation`; a retry while the first request is still running is
    a `409 conflict`. Use a fresh random key per intended action, and reuse it
    only to retry that action.

    ### External references

    Customers, items, documents, payments and expenses carry `external_refs`:
    links to the same record in another system, as
    `{"system", "id", "url", "label"}`. Set them on create or update (an update
    replaces the whole list). `system` and `id` are required, `system` must not
    contain `:`, and `url` must be http or https.

    A `(system, id)` pair is unique per record type in a business. Reusing one
    fails with `409 duplicate-external-ref` and `existing_id` naming the record
    that holds it, so a sync can create-or-find in one call.

    Look a record up by your own id with `?external_ref=<system>:<id>` on any
    of those list endpoints, for example
    `GET /v1/businesses/{businessID}/customers?external_ref=crm:4711`.

    ### Errors

    Errors are `application/problem+json` (RFC 9457):

    ```json
    {"type": "validation", "title": "The request is not valid", "status": 422,
     "detail": "name: is required", "errors": [{"field": "name", "message": "is required"}]}
    ```

    Switch on `type`, show `detail` to a person, and use `errors[].field` to
    point at the input. Request bodies are strict: an unknown field is a
    `422 validation` naming that field. See the `ProblemType` schema for every
    type and its status.

    ### Pagination

    List endpoints return `{"items": [...], "next_cursor": "..."}`, newest
    first. Pass `next_cursor` back as `?cursor=` for the next page; it is
    `null` on the last page. `?limit=` defaults to 50 and is capped at 200.
    Lists that are always complete (categories, deliveries) use the same
    envelope with `next_cursor: null`.

    ### Drafts and AI

    Quotes start as drafts. An invoice is issued and posted to the books when
    created, unless you send `"draft": true`; issue a draft later with
    `POST /documents/{id}/convert`. AI clients should create drafts and set
    `created_by_ai: true`, and let the person approve, issue and send.
tags:
  - name: Public
    description: Customer-facing pages reached from a sent link. No sign-in.
  - name: Reports
    description: Summary, job profit and the accountant's reports.
  - name: Attachments
    description: Receipt and file uploads.
  - name: Expenses
    description: Money out, with receipts, optionally tagged to a job.
  - name: Payments
    description: Money in, applied to invoices, and cash sales.
  - name: Documents
    description: One record that moves quote, work order, invoice.
  - name: Categories
    description: 'Income and expense categories: the accounts behind the scenes, by Schedule C line.'
  - name: Items
    description: Saved parts, labor, fees and discounts for document lines.
  - name: Customers
    description: People and companies you bill.
  - name: Settings
    description: Business details, sales tax, lock date and number series.
  - name: Session
    description: Sign-in, the signed-in user and creating a business (/bff).
paths:
  /bff/businesses:
    post:
      operationId: Session_createBusiness
      description: Create a business. The caller becomes its owner.
      parameters:
        - $ref: '#/components/parameters/Csrf'
      responses:
        '201':
          description: The request has succeeded and a new resource has been created as a result.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Membership'
        '400':
          description: The body is not valid JSON (`invalid-request`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '401':
          description: Not signed in (`unauthenticated`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '403':
          description: CSRF check failed or no permission (`csrf-failed`, `permission-denied`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '422':
          description: The request is not valid (`validation`, `unbalanced`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Session
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/BusinessCreate'
  /bff/callback:
    get:
      operationId: Session_callback
      description: The identity provider's redirect target. Sets `otazio_session` and `otazio_csrf`.
      parameters:
        - name: code
          in: query
          required: false
          schema:
            type: string
          explode: false
        - name: state
          in: query
          required: false
          schema:
            type: string
          explode: false
      responses:
        '302':
          description: Redirection
          headers:
            location:
              required: true
              schema:
                type: string
        '400':
          description: The body is not valid JSON (`invalid-request`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '401':
          description: Not signed in (`unauthenticated`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Session
      security:
        - {}
  /bff/login:
    get:
      operationId: Session_login
      description: 'Start sign-in: redirects to the identity provider, then back to `return`.'
      parameters:
        - name: return
          in: query
          required: false
          description: A same-site path to land on after sign-in. Defaults to `/`.
          schema:
            type: string
          explode: false
      responses:
        '302':
          description: Redirection
          headers:
            location:
              required: true
              schema:
                type: string
      tags:
        - Session
      security:
        - {}
  /bff/logout:
    post:
      operationId: Session_logout
      description: End the session and clear the cookies.
      parameters:
        - $ref: '#/components/parameters/Csrf'
      responses:
        '200':
          description: The request has succeeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/LogoutResult'
        '403':
          description: CSRF check failed or no permission (`csrf-failed`, `permission-denied`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Session
  /bff/me:
    get:
      operationId: Session_me
      description: The signed-in user and their businesses. Re-issues the `otazio_csrf` cookie.
      parameters: []
      responses:
        '200':
          description: The request has succeeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Me'
        '401':
          description: Not signed in (`unauthenticated`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Session
  /p/{token}:
    get:
      operationId: PublicPages_view
      description: The customer's view of a sent quote or invoice, with a PDF link and, for a quote, an approve button.
      parameters:
        - $ref: '#/components/parameters/TokenPath'
      responses:
        '200':
          description: The request has succeeded.
          content:
            text/html; charset=utf-8:
              schema:
                type: string
        '404':
          description: The link is not valid (an HTML page).
          content:
            text/html; charset=utf-8:
              schema:
                type: string
      tags:
        - Public
      security:
        - {}
  /p/{token}/approve:
    post:
      operationId: PublicPages_approve
      description: |-
        The customer approves the quote. A browser form post is redirected back
        to the page; a client sending `Accept: application/json` gets JSON.
      parameters:
        - $ref: '#/components/parameters/TokenPath'
        - name: accept
          in: header
          required: false
          schema:
            type: string
      responses:
        '200':
          description: The request has succeeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicApproval'
        '303':
          description: Redirection
          headers:
            location:
              required: true
              description: Back to the document page.
              schema:
                type: string
        '404':
          description: The link is not valid (an HTML page).
          content:
            text/html; charset=utf-8:
              schema:
                type: string
        '409':
          description: State conflict (`conflict`, `duplicate-external-ref`, `immutable`, `period-locked`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Public
      security:
        - {}
  /p/{token}/pdf:
    get:
      operationId: PublicPages_pdf
      description: Download the document as a PDF.
      parameters:
        - $ref: '#/components/parameters/TokenPath'
      responses:
        '200':
          description: The request has succeeded.
          headers:
            content-disposition:
              required: true
              schema:
                type: string
          content:
            application/pdf:
              schema:
                contentMediaType: application/pdf
        '404':
          description: The link is not valid (an HTML page).
          content:
            text/html; charset=utf-8:
              schema:
                type: string
        '502':
          description: A dependency failed (`upstream`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Public
      security:
        - {}
  /v1/businesses/{businessID}/attachments:
    post:
      operationId: Attachments_upload
      description: Upload a receipt or file.
      parameters:
        - $ref: '#/components/parameters/BusinessPath'
        - $ref: '#/components/parameters/Csrf'
        - $ref: '#/components/parameters/Idempotency'
      responses:
        '201':
          description: The request has succeeded and a new resource has been created as a result.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Attachment'
        '401':
          description: Not signed in (`unauthenticated`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '403':
          description: CSRF check failed or no permission (`csrf-failed`, `permission-denied`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '404':
          description: No such record or business (`not-found`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '409':
          description: State conflict (`conflict`, `duplicate-external-ref`, `immutable`, `period-locked`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '422':
          description: The request is not valid (`validation`, `unbalanced`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '502':
          description: A dependency failed (`upstream`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '503':
          description: The business's data could not be opened (`tenant-unavailable`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Attachments
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/UploadForm'
            encoding:
              file:
                contentType: '*/*'
    get:
      operationId: Attachments_download
      description: Download an attachment by key.
      parameters:
        - $ref: '#/components/parameters/BusinessPath'
        - name: key
          in: query
          required: true
          description: The key returned by upload.
          schema:
            type: string
          explode: false
      responses:
        '200':
          description: The request has succeeded.
          content:
            '*/*':
              schema:
                contentMediaType: '*/*'
        '401':
          description: Not signed in (`unauthenticated`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '403':
          description: CSRF check failed or no permission (`csrf-failed`, `permission-denied`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '404':
          description: No such record or business (`not-found`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '422':
          description: The request is not valid (`validation`, `unbalanced`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '503':
          description: The business's data could not be opened (`tenant-unavailable`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Attachments
  /v1/businesses/{businessID}/categories:
    get:
      operationId: Categories_list
      description: 'List all categories (accounts) by code. Not paged: `next_cursor` is always `null`.'
      parameters:
        - $ref: '#/components/parameters/BusinessPath'
        - name: type
          in: query
          required: false
          description: Only this account type, e.g. `expense`.
          schema:
            $ref: '#/components/schemas/AccountType'
          explode: false
      responses:
        '200':
          description: The request has succeeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CategoryList'
        '401':
          description: Not signed in (`unauthenticated`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '403':
          description: CSRF check failed or no permission (`csrf-failed`, `permission-denied`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '404':
          description: No such record or business (`not-found`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '422':
          description: The request is not valid (`validation`, `unbalanced`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '503':
          description: The business's data could not be opened (`tenant-unavailable`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Categories
    post:
      operationId: Categories_create
      description: Create an income or expense category.
      parameters:
        - $ref: '#/components/parameters/BusinessPath'
        - $ref: '#/components/parameters/Csrf'
        - $ref: '#/components/parameters/Idempotency'
      responses:
        '201':
          description: The request has succeeded and a new resource has been created as a result.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Category'
        '401':
          description: Not signed in (`unauthenticated`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '403':
          description: CSRF check failed or no permission (`csrf-failed`, `permission-denied`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '404':
          description: No such record or business (`not-found`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '409':
          description: State conflict (`conflict`, `duplicate-external-ref`, `immutable`, `period-locked`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '422':
          description: The request is not valid (`validation`, `unbalanced`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '503':
          description: The business's data could not be opened (`tenant-unavailable`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Categories
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CategoryCreate'
  /v1/businesses/{businessID}/categories/{id}:
    get:
      operationId: Categories_get
      description: Get a category.
      parameters:
        - $ref: '#/components/parameters/BusinessPath'
        - $ref: '#/components/parameters/RecordPath.id'
      responses:
        '200':
          description: The request has succeeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Category'
        '401':
          description: Not signed in (`unauthenticated`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '403':
          description: CSRF check failed or no permission (`csrf-failed`, `permission-denied`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '404':
          description: No such record or business (`not-found`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '422':
          description: The request is not valid (`validation`, `unbalanced`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '503':
          description: The business's data could not be opened (`tenant-unavailable`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Categories
    patch:
      operationId: Categories_update
      description: Rename, retire or move a category to another Schedule C line.
      parameters:
        - $ref: '#/components/parameters/BusinessPath'
        - $ref: '#/components/parameters/RecordPath.id'
        - $ref: '#/components/parameters/Csrf'
      responses:
        '200':
          description: The request has succeeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Category'
        '401':
          description: Not signed in (`unauthenticated`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '403':
          description: CSRF check failed or no permission (`csrf-failed`, `permission-denied`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '404':
          description: No such record or business (`not-found`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '409':
          description: State conflict (`conflict`, `duplicate-external-ref`, `immutable`, `period-locked`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '422':
          description: The request is not valid (`validation`, `unbalanced`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '503':
          description: The business's data could not be opened (`tenant-unavailable`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Categories
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CategoryPatch'
  /v1/businesses/{businessID}/customers:
    get:
      operationId: Customers_list
      description: List customers, newest first. `q` searches name, email and phone.
      parameters:
        - $ref: '#/components/parameters/BusinessPath'
        - $ref: '#/components/parameters/Paging.limit'
        - $ref: '#/components/parameters/Paging.cursor'
        - $ref: '#/components/parameters/Searchable.q'
        - $ref: '#/components/parameters/Searchable.external_ref'
      responses:
        '200':
          description: The request has succeeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CustomerList'
        '401':
          description: Not signed in (`unauthenticated`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '403':
          description: CSRF check failed or no permission (`csrf-failed`, `permission-denied`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '404':
          description: No such record or business (`not-found`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '422':
          description: The request is not valid (`validation`, `unbalanced`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '503':
          description: The business's data could not be opened (`tenant-unavailable`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Customers
    post:
      operationId: Customers_create
      description: Create a customer.
      parameters:
        - $ref: '#/components/parameters/BusinessPath'
        - $ref: '#/components/parameters/Csrf'
        - $ref: '#/components/parameters/Idempotency'
      responses:
        '201':
          description: The request has succeeded and a new resource has been created as a result.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Customer'
        '401':
          description: Not signed in (`unauthenticated`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '403':
          description: CSRF check failed or no permission (`csrf-failed`, `permission-denied`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '404':
          description: No such record or business (`not-found`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '409':
          description: State conflict (`conflict`, `duplicate-external-ref`, `immutable`, `period-locked`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '422':
          description: The request is not valid (`validation`, `unbalanced`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '503':
          description: The business's data could not be opened (`tenant-unavailable`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Customers
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CustomerCreate'
  /v1/businesses/{businessID}/customers/{id}:
    get:
      operationId: Customers_get
      description: Get a customer.
      parameters:
        - $ref: '#/components/parameters/BusinessPath'
        - $ref: '#/components/parameters/RecordPath.id'
      responses:
        '200':
          description: The request has succeeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Customer'
        '401':
          description: Not signed in (`unauthenticated`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '403':
          description: CSRF check failed or no permission (`csrf-failed`, `permission-denied`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '404':
          description: No such record or business (`not-found`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '422':
          description: The request is not valid (`validation`, `unbalanced`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '503':
          description: The business's data could not be opened (`tenant-unavailable`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Customers
    patch:
      operationId: Customers_update
      description: Update a customer.
      parameters:
        - $ref: '#/components/parameters/BusinessPath'
        - $ref: '#/components/parameters/RecordPath.id'
        - $ref: '#/components/parameters/Csrf'
      responses:
        '200':
          description: The request has succeeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Customer'
        '401':
          description: Not signed in (`unauthenticated`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '403':
          description: CSRF check failed or no permission (`csrf-failed`, `permission-denied`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '404':
          description: No such record or business (`not-found`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '409':
          description: State conflict (`conflict`, `duplicate-external-ref`, `immutable`, `period-locked`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '422':
          description: The request is not valid (`validation`, `unbalanced`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '503':
          description: The business's data could not be opened (`tenant-unavailable`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Customers
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CustomerPatch'
  /v1/businesses/{businessID}/documents:
    get:
      operationId: Documents_list
      description: List documents, newest first. `q` searches number, customer name and notes.
      parameters:
        - $ref: '#/components/parameters/BusinessPath'
        - $ref: '#/components/parameters/Paging.limit'
        - $ref: '#/components/parameters/Paging.cursor'
        - $ref: '#/components/parameters/Searchable.q'
        - $ref: '#/components/parameters/Searchable.external_ref'
        - name: kind
          in: query
          required: false
          schema:
            $ref: '#/components/schemas/DocumentKind'
          explode: false
        - name: status
          in: query
          required: false
          schema:
            $ref: '#/components/schemas/DocumentStatus'
          explode: false
        - name: customer_id
          in: query
          required: false
          schema:
            $ref: '#/components/schemas/Id'
          explode: false
      responses:
        '200':
          description: The request has succeeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DocumentList'
        '401':
          description: Not signed in (`unauthenticated`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '403':
          description: CSRF check failed or no permission (`csrf-failed`, `permission-denied`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '404':
          description: No such record or business (`not-found`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '422':
          description: The request is not valid (`validation`, `unbalanced`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '503':
          description: The business's data could not be opened (`tenant-unavailable`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Documents
    post:
      operationId: Documents_create
      description: |-
        Create a quote, work order or invoice. An invoice is issued and posted to
        the books at once unless `draft` is true.
      parameters:
        - $ref: '#/components/parameters/BusinessPath'
        - $ref: '#/components/parameters/Csrf'
        - $ref: '#/components/parameters/Idempotency'
      responses:
        '201':
          description: The request has succeeded and a new resource has been created as a result.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Document'
        '401':
          description: Not signed in (`unauthenticated`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '403':
          description: CSRF check failed or no permission (`csrf-failed`, `permission-denied`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '404':
          description: No such record or business (`not-found`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '409':
          description: State conflict (`conflict`, `duplicate-external-ref`, `immutable`, `period-locked`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '422':
          description: The request is not valid (`validation`, `unbalanced`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '503':
          description: The business's data could not be opened (`tenant-unavailable`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Documents
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/DocumentCreate'
  /v1/businesses/{businessID}/documents/{id}:
    get:
      operationId: Documents_get
      description: Get a document with its lines and totals.
      parameters:
        - $ref: '#/components/parameters/BusinessPath'
        - $ref: '#/components/parameters/RecordPath.id'
      responses:
        '200':
          description: The request has succeeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Document'
        '401':
          description: Not signed in (`unauthenticated`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '403':
          description: CSRF check failed or no permission (`csrf-failed`, `permission-denied`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '404':
          description: No such record or business (`not-found`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '422':
          description: The request is not valid (`validation`, `unbalanced`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '503':
          description: The business's data could not be opened (`tenant-unavailable`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Documents
    patch:
      operationId: Documents_update
      description: Update a document.
      parameters:
        - $ref: '#/components/parameters/BusinessPath'
        - $ref: '#/components/parameters/RecordPath.id'
        - $ref: '#/components/parameters/Csrf'
      responses:
        '200':
          description: The request has succeeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Document'
        '401':
          description: Not signed in (`unauthenticated`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '403':
          description: CSRF check failed or no permission (`csrf-failed`, `permission-denied`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '404':
          description: No such record or business (`not-found`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '409':
          description: State conflict (`conflict`, `duplicate-external-ref`, `immutable`, `period-locked`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '422':
          description: The request is not valid (`validation`, `unbalanced`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '503':
          description: The business's data could not be opened (`tenant-unavailable`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Documents
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/DocumentPatch'
  /v1/businesses/{businessID}/documents/{id}/approve:
    post:
      operationId: Documents_approve
      description: Mark a quote approved (as the user).
      parameters:
        - $ref: '#/components/parameters/BusinessPath'
        - $ref: '#/components/parameters/RecordPath.id'
        - $ref: '#/components/parameters/Csrf'
        - $ref: '#/components/parameters/Idempotency'
      responses:
        '200':
          description: The request has succeeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Document'
        '401':
          description: Not signed in (`unauthenticated`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '403':
          description: CSRF check failed or no permission (`csrf-failed`, `permission-denied`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '404':
          description: No such record or business (`not-found`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '409':
          description: State conflict (`conflict`, `duplicate-external-ref`, `immutable`, `period-locked`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '422':
          description: The request is not valid (`validation`, `unbalanced`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '503':
          description: The business's data could not be opened (`tenant-unavailable`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Documents
  /v1/businesses/{businessID}/documents/{id}/convert:
    post:
      operationId: Documents_convert
      description: |-
        Move a document to its next stage: quote to work order, work order to
        invoice (posts), draft invoice to issued invoice (posts).
      parameters:
        - $ref: '#/components/parameters/BusinessPath'
        - $ref: '#/components/parameters/RecordPath.id'
        - $ref: '#/components/parameters/Csrf'
        - $ref: '#/components/parameters/Idempotency'
      responses:
        '200':
          description: The request has succeeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Document'
        '401':
          description: Not signed in (`unauthenticated`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '403':
          description: CSRF check failed or no permission (`csrf-failed`, `permission-denied`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '404':
          description: No such record or business (`not-found`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '409':
          description: State conflict (`conflict`, `duplicate-external-ref`, `immutable`, `period-locked`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '422':
          description: The request is not valid (`validation`, `unbalanced`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '503':
          description: The business's data could not be opened (`tenant-unavailable`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Documents
      requestBody:
        required: false
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ConvertInput'
  /v1/businesses/{businessID}/documents/{id}/deliveries:
    get:
      operationId: Documents_deliveries
      description: Every send of the document. Not paged.
      parameters:
        - $ref: '#/components/parameters/BusinessPath'
        - $ref: '#/components/parameters/RecordPath.id'
      responses:
        '200':
          description: The request has succeeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DeliveryList'
        '401':
          description: Not signed in (`unauthenticated`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '403':
          description: CSRF check failed or no permission (`csrf-failed`, `permission-denied`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '404':
          description: No such record or business (`not-found`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '422':
          description: The request is not valid (`validation`, `unbalanced`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '503':
          description: The business's data could not be opened (`tenant-unavailable`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Documents
  /v1/businesses/{businessID}/documents/{id}/pdf:
    get:
      operationId: Documents_pdf
      description: The document as a PDF (rendered if missing).
      parameters:
        - $ref: '#/components/parameters/BusinessPath'
        - $ref: '#/components/parameters/RecordPath.id'
        - name: download
          in: query
          required: false
          description: 'Any value: download as an attachment.'
          schema:
            type: string
          explode: false
      responses:
        '200':
          description: The request has succeeded.
          headers:
            content-disposition:
              required: true
              description: '`inline`, or `attachment` with `?download=1`.'
              schema:
                type: string
          content:
            application/pdf:
              schema:
                contentMediaType: application/pdf
        '401':
          description: Not signed in (`unauthenticated`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '403':
          description: CSRF check failed or no permission (`csrf-failed`, `permission-denied`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '404':
          description: No such record or business (`not-found`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '422':
          description: The request is not valid (`validation`, `unbalanced`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '502':
          description: A dependency failed (`upstream`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '503':
          description: The business's data could not be opened (`tenant-unavailable`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Documents
  /v1/businesses/{businessID}/documents/{id}/send:
    post:
      operationId: Documents_send
      description: |-
        Email the document to the customer: renders the PDF, emails a link to
        `/p/{token}` with the PDF attached, and records a delivery. A draft
        invoice must be issued first. A failed email is still recorded and
        returns 502.
      parameters:
        - $ref: '#/components/parameters/BusinessPath'
        - $ref: '#/components/parameters/RecordPath.id'
        - $ref: '#/components/parameters/Csrf'
        - $ref: '#/components/parameters/Idempotency'
      responses:
        '200':
          description: The request has succeeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SendResult'
        '401':
          description: Not signed in (`unauthenticated`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '403':
          description: CSRF check failed or no permission (`csrf-failed`, `permission-denied`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '404':
          description: No such record or business (`not-found`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '409':
          description: State conflict (`conflict`, `duplicate-external-ref`, `immutable`, `period-locked`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '422':
          description: The request is not valid (`validation`, `unbalanced`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '502':
          description: A dependency failed (`upstream`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '503':
          description: The business's data could not be opened (`tenant-unavailable`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Documents
      requestBody:
        required: false
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SendInput'
  /v1/businesses/{businessID}/documents/{id}/void:
    post:
      operationId: Documents_cancel
      description: Void a document. A posted invoice is reversed; void its payments first.
      parameters:
        - $ref: '#/components/parameters/BusinessPath'
        - $ref: '#/components/parameters/RecordPath.id'
        - $ref: '#/components/parameters/Csrf'
        - $ref: '#/components/parameters/Idempotency'
      responses:
        '200':
          description: The request has succeeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Document'
        '401':
          description: Not signed in (`unauthenticated`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '403':
          description: CSRF check failed or no permission (`csrf-failed`, `permission-denied`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '404':
          description: No such record or business (`not-found`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '409':
          description: State conflict (`conflict`, `duplicate-external-ref`, `immutable`, `period-locked`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '422':
          description: The request is not valid (`validation`, `unbalanced`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '503':
          description: The business's data could not be opened (`tenant-unavailable`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Documents
      requestBody:
        required: false
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/VoidDocumentInput'
  /v1/businesses/{businessID}/expenses:
    get:
      operationId: Expenses_list
      description: List expenses, newest first. `q` searches vendor, memo and number.
      parameters:
        - $ref: '#/components/parameters/BusinessPath'
        - $ref: '#/components/parameters/Paging.limit'
        - $ref: '#/components/parameters/Paging.cursor'
        - $ref: '#/components/parameters/Searchable.q'
        - $ref: '#/components/parameters/Searchable.external_ref'
        - name: document_id
          in: query
          required: false
          description: Expenses tagged to this job.
          schema:
            $ref: '#/components/schemas/Id'
          explode: false
        - name: category_id
          in: query
          required: false
          schema:
            $ref: '#/components/schemas/Id'
          explode: false
        - name: from
          in: query
          required: false
          schema:
            $ref: '#/components/schemas/Date'
          explode: false
        - name: to
          in: query
          required: false
          schema:
            $ref: '#/components/schemas/Date'
          explode: false
      responses:
        '200':
          description: The request has succeeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ExpenseList'
        '401':
          description: Not signed in (`unauthenticated`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '403':
          description: CSRF check failed or no permission (`csrf-failed`, `permission-denied`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '404':
          description: No such record or business (`not-found`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '422':
          description: The request is not valid (`validation`, `unbalanced`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '503':
          description: The business's data could not be opened (`tenant-unavailable`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Expenses
    post:
      operationId: Expenses_create
      description: Record money spent. Posts to the books.
      parameters:
        - $ref: '#/components/parameters/BusinessPath'
        - $ref: '#/components/parameters/Csrf'
        - $ref: '#/components/parameters/Idempotency'
      responses:
        '201':
          description: The request has succeeded and a new resource has been created as a result.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Expense'
        '401':
          description: Not signed in (`unauthenticated`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '403':
          description: CSRF check failed or no permission (`csrf-failed`, `permission-denied`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '404':
          description: No such record or business (`not-found`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '409':
          description: State conflict (`conflict`, `duplicate-external-ref`, `immutable`, `period-locked`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '422':
          description: The request is not valid (`validation`, `unbalanced`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '503':
          description: The business's data could not be opened (`tenant-unavailable`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Expenses
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ExpenseCreate'
  /v1/businesses/{businessID}/expenses/{id}:
    get:
      operationId: Expenses_get
      description: Get an expense.
      parameters:
        - $ref: '#/components/parameters/BusinessPath'
        - $ref: '#/components/parameters/RecordPath.id'
      responses:
        '200':
          description: The request has succeeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Expense'
        '401':
          description: Not signed in (`unauthenticated`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '403':
          description: CSRF check failed or no permission (`csrf-failed`, `permission-denied`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '404':
          description: No such record or business (`not-found`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '422':
          description: The request is not valid (`validation`, `unbalanced`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '503':
          description: The business's data could not be opened (`tenant-unavailable`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Expenses
    patch:
      operationId: Expenses_update
      description: Update an expense.
      parameters:
        - $ref: '#/components/parameters/BusinessPath'
        - $ref: '#/components/parameters/RecordPath.id'
        - $ref: '#/components/parameters/Csrf'
      responses:
        '200':
          description: The request has succeeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Expense'
        '401':
          description: Not signed in (`unauthenticated`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '403':
          description: CSRF check failed or no permission (`csrf-failed`, `permission-denied`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '404':
          description: No such record or business (`not-found`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '409':
          description: State conflict (`conflict`, `duplicate-external-ref`, `immutable`, `period-locked`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '422':
          description: The request is not valid (`validation`, `unbalanced`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '503':
          description: The business's data could not be opened (`tenant-unavailable`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Expenses
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ExpensePatch'
  /v1/businesses/{businessID}/expenses/{id}/void:
    post:
      operationId: Expenses_cancel
      description: Void an expense (posts a reversal).
      parameters:
        - $ref: '#/components/parameters/BusinessPath'
        - $ref: '#/components/parameters/RecordPath.id'
        - $ref: '#/components/parameters/Csrf'
        - $ref: '#/components/parameters/Idempotency'
      responses:
        '200':
          description: The request has succeeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Expense'
        '401':
          description: Not signed in (`unauthenticated`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '403':
          description: CSRF check failed or no permission (`csrf-failed`, `permission-denied`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '404':
          description: No such record or business (`not-found`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '409':
          description: State conflict (`conflict`, `duplicate-external-ref`, `immutable`, `period-locked`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '422':
          description: The request is not valid (`validation`, `unbalanced`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '503':
          description: The business's data could not be opened (`tenant-unavailable`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Expenses
      requestBody:
        required: false
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/VoidDateInput'
  /v1/businesses/{businessID}/items:
    get:
      operationId: Items_list
      description: List items, newest first.
      parameters:
        - $ref: '#/components/parameters/BusinessPath'
        - $ref: '#/components/parameters/Paging.limit'
        - $ref: '#/components/parameters/Paging.cursor'
        - $ref: '#/components/parameters/Searchable.q'
        - $ref: '#/components/parameters/Searchable.external_ref'
        - name: kind
          in: query
          required: false
          description: Only this kind.
          schema:
            $ref: '#/components/schemas/LineKind'
          explode: false
        - name: active
          in: query
          required: false
          description: Only active (`true`) or inactive (`false`) items.
          schema:
            type: boolean
          explode: false
      responses:
        '200':
          description: The request has succeeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ItemList'
        '401':
          description: Not signed in (`unauthenticated`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '403':
          description: CSRF check failed or no permission (`csrf-failed`, `permission-denied`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '404':
          description: No such record or business (`not-found`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '422':
          description: The request is not valid (`validation`, `unbalanced`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '503':
          description: The business's data could not be opened (`tenant-unavailable`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Items
    post:
      operationId: Items_create
      description: Create an item.
      parameters:
        - $ref: '#/components/parameters/BusinessPath'
        - $ref: '#/components/parameters/Csrf'
        - $ref: '#/components/parameters/Idempotency'
      responses:
        '201':
          description: The request has succeeded and a new resource has been created as a result.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Item'
        '401':
          description: Not signed in (`unauthenticated`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '403':
          description: CSRF check failed or no permission (`csrf-failed`, `permission-denied`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '404':
          description: No such record or business (`not-found`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '409':
          description: State conflict (`conflict`, `duplicate-external-ref`, `immutable`, `period-locked`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '422':
          description: The request is not valid (`validation`, `unbalanced`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '503':
          description: The business's data could not be opened (`tenant-unavailable`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Items
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ItemCreate'
  /v1/businesses/{businessID}/items/{id}:
    get:
      operationId: Items_get
      description: Get an item.
      parameters:
        - $ref: '#/components/parameters/BusinessPath'
        - $ref: '#/components/parameters/RecordPath.id'
      responses:
        '200':
          description: The request has succeeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Item'
        '401':
          description: Not signed in (`unauthenticated`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '403':
          description: CSRF check failed or no permission (`csrf-failed`, `permission-denied`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '404':
          description: No such record or business (`not-found`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '422':
          description: The request is not valid (`validation`, `unbalanced`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '503':
          description: The business's data could not be opened (`tenant-unavailable`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Items
    patch:
      operationId: Items_update
      description: Update an item.
      parameters:
        - $ref: '#/components/parameters/BusinessPath'
        - $ref: '#/components/parameters/RecordPath.id'
        - $ref: '#/components/parameters/Csrf'
      responses:
        '200':
          description: The request has succeeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Item'
        '401':
          description: Not signed in (`unauthenticated`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '403':
          description: CSRF check failed or no permission (`csrf-failed`, `permission-denied`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '404':
          description: No such record or business (`not-found`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '409':
          description: State conflict (`conflict`, `duplicate-external-ref`, `immutable`, `period-locked`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '422':
          description: The request is not valid (`validation`, `unbalanced`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '503':
          description: The business's data could not be opened (`tenant-unavailable`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Items
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ItemPatch'
  /v1/businesses/{businessID}/journal:
    get:
      operationId: Reports_journal
      description: Posted journal entries with lines (accountant view).
      parameters:
        - $ref: '#/components/parameters/BusinessPath'
        - name: from
          in: query
          required: false
          description: Defaults to the first of this month.
          schema:
            $ref: '#/components/schemas/Date'
          explode: false
        - name: to
          in: query
          required: false
          description: Defaults to today.
          schema:
            $ref: '#/components/schemas/Date'
          explode: false
      responses:
        '200':
          description: The request has succeeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Journal'
        '401':
          description: Not signed in (`unauthenticated`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '403':
          description: CSRF check failed or no permission (`csrf-failed`, `permission-denied`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '404':
          description: No such record or business (`not-found`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '422':
          description: The request is not valid (`validation`, `unbalanced`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '503':
          description: The business's data could not be opened (`tenant-unavailable`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Reports
  /v1/businesses/{businessID}/payments:
    get:
      operationId: Payments_list
      description: List payments, newest first. `q` searches number, reference and customer name.
      parameters:
        - $ref: '#/components/parameters/BusinessPath'
        - $ref: '#/components/parameters/Paging.limit'
        - $ref: '#/components/parameters/Paging.cursor'
        - $ref: '#/components/parameters/Searchable.q'
        - $ref: '#/components/parameters/Searchable.external_ref'
        - name: customer_id
          in: query
          required: false
          schema:
            $ref: '#/components/schemas/Id'
          explode: false
        - name: status
          in: query
          required: false
          schema:
            type: string
            enum:
              - posted
              - void
          explode: false
      responses:
        '200':
          description: The request has succeeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PaymentList'
        '401':
          description: Not signed in (`unauthenticated`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '403':
          description: CSRF check failed or no permission (`csrf-failed`, `permission-denied`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '404':
          description: No such record or business (`not-found`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '422':
          description: The request is not valid (`validation`, `unbalanced`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '503':
          description: The business's data could not be opened (`tenant-unavailable`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Payments
    post:
      operationId: Payments_create
      description: Record money received and apply it to invoices. Posts to the books.
      parameters:
        - $ref: '#/components/parameters/BusinessPath'
        - $ref: '#/components/parameters/Csrf'
        - $ref: '#/components/parameters/Idempotency'
      responses:
        '201':
          description: The request has succeeded and a new resource has been created as a result.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Payment'
        '401':
          description: Not signed in (`unauthenticated`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '403':
          description: CSRF check failed or no permission (`csrf-failed`, `permission-denied`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '404':
          description: No such record or business (`not-found`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '409':
          description: State conflict (`conflict`, `duplicate-external-ref`, `immutable`, `period-locked`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '422':
          description: The request is not valid (`validation`, `unbalanced`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '503':
          description: The business's data could not be opened (`tenant-unavailable`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Payments
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PaymentCreate'
  /v1/businesses/{businessID}/payments/{id}:
    get:
      operationId: Payments_get
      description: Get a payment.
      parameters:
        - $ref: '#/components/parameters/BusinessPath'
        - $ref: '#/components/parameters/RecordPath.id'
      responses:
        '200':
          description: The request has succeeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Payment'
        '401':
          description: Not signed in (`unauthenticated`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '403':
          description: CSRF check failed or no permission (`csrf-failed`, `permission-denied`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '404':
          description: No such record or business (`not-found`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '422':
          description: The request is not valid (`validation`, `unbalanced`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '503':
          description: The business's data could not be opened (`tenant-unavailable`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Payments
  /v1/businesses/{businessID}/payments/{id}/void:
    post:
      operationId: Payments_cancel
      description: Void a payment; its invoices become unpaid again.
      parameters:
        - $ref: '#/components/parameters/BusinessPath'
        - $ref: '#/components/parameters/RecordPath.id'
        - $ref: '#/components/parameters/Csrf'
        - $ref: '#/components/parameters/Idempotency'
      responses:
        '200':
          description: The request has succeeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Payment'
        '401':
          description: Not signed in (`unauthenticated`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '403':
          description: CSRF check failed or no permission (`csrf-failed`, `permission-denied`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '404':
          description: No such record or business (`not-found`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '409':
          description: State conflict (`conflict`, `duplicate-external-ref`, `immutable`, `period-locked`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '422':
          description: The request is not valid (`validation`, `unbalanced`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '503':
          description: The business's data could not be opened (`tenant-unavailable`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Payments
      requestBody:
        required: false
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/VoidDateInput'
  /v1/businesses/{businessID}/reports/ar-aging:
    get:
      operationId: Reports_arAging
      description: Accounts receivable aging; ties to the AR account.
      parameters:
        - $ref: '#/components/parameters/BusinessPath'
        - $ref: '#/components/parameters/AsOf'
      responses:
        '200':
          description: The request has succeeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ARAging'
        '401':
          description: Not signed in (`unauthenticated`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '403':
          description: CSRF check failed or no permission (`csrf-failed`, `permission-denied`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '404':
          description: No such record or business (`not-found`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '422':
          description: The request is not valid (`validation`, `unbalanced`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '503':
          description: The business's data could not be opened (`tenant-unavailable`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Reports
  /v1/businesses/{businessID}/reports/balance-sheet:
    get:
      operationId: Reports_balanceSheet
      description: Balance sheet.
      parameters:
        - $ref: '#/components/parameters/BusinessPath'
        - $ref: '#/components/parameters/AsOf'
      responses:
        '200':
          description: The request has succeeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BalanceSheet'
        '401':
          description: Not signed in (`unauthenticated`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '403':
          description: CSRF check failed or no permission (`csrf-failed`, `permission-denied`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '404':
          description: No such record or business (`not-found`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '422':
          description: The request is not valid (`validation`, `unbalanced`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '503':
          description: The business's data could not be opened (`tenant-unavailable`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Reports
  /v1/businesses/{businessID}/reports/job-profit:
    get:
      operationId: Reports_jobProfit
      description: Billed, costs, profit and margin per work order and invoice (not void).
      parameters:
        - $ref: '#/components/parameters/BusinessPath'
        - name: document_id
          in: query
          required: false
          description: Only this job.
          schema:
            $ref: '#/components/schemas/Id'
          explode: false
      responses:
        '200':
          description: The request has succeeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JobProfitReport'
        '401':
          description: Not signed in (`unauthenticated`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '403':
          description: CSRF check failed or no permission (`csrf-failed`, `permission-denied`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '404':
          description: No such record or business (`not-found`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '422':
          description: The request is not valid (`validation`, `unbalanced`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '503':
          description: The business's data could not be opened (`tenant-unavailable`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Reports
  /v1/businesses/{businessID}/reports/profit-and-loss:
    get:
      operationId: Reports_profitAndLoss
      description: Profit and loss (accrual).
      parameters:
        - $ref: '#/components/parameters/BusinessPath'
        - name: from
          in: query
          required: false
          description: Defaults to January 1 of this year.
          schema:
            $ref: '#/components/schemas/Date'
          explode: false
        - name: to
          in: query
          required: false
          description: Defaults to today.
          schema:
            $ref: '#/components/schemas/Date'
          explode: false
      responses:
        '200':
          description: The request has succeeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProfitAndLoss'
        '401':
          description: Not signed in (`unauthenticated`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '403':
          description: CSRF check failed or no permission (`csrf-failed`, `permission-denied`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '404':
          description: No such record or business (`not-found`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '422':
          description: The request is not valid (`validation`, `unbalanced`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '503':
          description: The business's data could not be opened (`tenant-unavailable`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Reports
  /v1/businesses/{businessID}/reports/schedule-c:
    get:
      operationId: Reports_scheduleC
      description: Schedule C lines for a calendar year. Cash basis is derived from the accrual ledger.
      parameters:
        - $ref: '#/components/parameters/BusinessPath'
        - name: year
          in: query
          required: false
          description: Defaults to this year.
          schema:
            type: integer
            format: int32
          explode: false
        - name: basis
          in: query
          required: false
          schema:
            type: string
            enum:
              - cash
              - accrual
            default: cash
          explode: false
      responses:
        '200':
          description: The request has succeeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ScheduleC'
        '401':
          description: Not signed in (`unauthenticated`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '403':
          description: CSRF check failed or no permission (`csrf-failed`, `permission-denied`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '404':
          description: No such record or business (`not-found`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '422':
          description: The request is not valid (`validation`, `unbalanced`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '503':
          description: The business's data could not be opened (`tenant-unavailable`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Reports
  /v1/businesses/{businessID}/reports/summary:
    get:
      operationId: Reports_summary
      description: Made this month, owed to you, you owe, cash and jobs in progress.
      parameters:
        - $ref: '#/components/parameters/BusinessPath'
        - $ref: '#/components/parameters/AsOf'
      responses:
        '200':
          description: The request has succeeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Summary'
        '401':
          description: Not signed in (`unauthenticated`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '403':
          description: CSRF check failed or no permission (`csrf-failed`, `permission-denied`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '404':
          description: No such record or business (`not-found`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '422':
          description: The request is not valid (`validation`, `unbalanced`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '503':
          description: The business's data could not be opened (`tenant-unavailable`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Reports
  /v1/businesses/{businessID}/reports/trial-balance:
    get:
      operationId: Reports_trialBalance
      description: Trial balance (accountant view).
      parameters:
        - $ref: '#/components/parameters/BusinessPath'
        - $ref: '#/components/parameters/AsOf'
      responses:
        '200':
          description: The request has succeeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TrialBalance'
        '401':
          description: Not signed in (`unauthenticated`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '403':
          description: CSRF check failed or no permission (`csrf-failed`, `permission-denied`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '404':
          description: No such record or business (`not-found`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '422':
          description: The request is not valid (`validation`, `unbalanced`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '503':
          description: The business's data could not be opened (`tenant-unavailable`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Reports
  /v1/businesses/{businessID}/sales:
    post:
      operationId: Sales_create
      description: 'Record a sale paid on the spot: creates an invoice and its payment together. Posts to the books.'
      parameters:
        - $ref: '#/components/parameters/BusinessPath'
        - $ref: '#/components/parameters/Csrf'
        - $ref: '#/components/parameters/Idempotency'
      responses:
        '201':
          description: The request has succeeded and a new resource has been created as a result.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Sale'
        '401':
          description: Not signed in (`unauthenticated`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '403':
          description: CSRF check failed or no permission (`csrf-failed`, `permission-denied`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '404':
          description: No such record or business (`not-found`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '409':
          description: State conflict (`conflict`, `duplicate-external-ref`, `immutable`, `period-locked`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '422':
          description: The request is not valid (`validation`, `unbalanced`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '503':
          description: The business's data could not be opened (`tenant-unavailable`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Payments
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SaleCreate'
  /v1/businesses/{businessID}/settings:
    get:
      operationId: SettingsApi_get
      description: Get the business settings.
      parameters:
        - $ref: '#/components/parameters/BusinessPath'
      responses:
        '200':
          description: The request has succeeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Settings'
        '401':
          description: Not signed in (`unauthenticated`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '403':
          description: CSRF check failed or no permission (`csrf-failed`, `permission-denied`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '404':
          description: No such record or business (`not-found`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '422':
          description: The request is not valid (`validation`, `unbalanced`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '503':
          description: The business's data could not be opened (`tenant-unavailable`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Settings
    patch:
      operationId: SettingsApi_update
      description: Update the business settings.
      parameters:
        - $ref: '#/components/parameters/BusinessPath'
        - $ref: '#/components/parameters/Csrf'
      responses:
        '200':
          description: The request has succeeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Settings'
        '401':
          description: Not signed in (`unauthenticated`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '403':
          description: CSRF check failed or no permission (`csrf-failed`, `permission-denied`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '404':
          description: No such record or business (`not-found`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '409':
          description: State conflict (`conflict`, `duplicate-external-ref`, `immutable`, `period-locked`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '422':
          description: The request is not valid (`validation`, `unbalanced`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '503':
          description: The business's data could not be opened (`tenant-unavailable`).
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      tags:
        - Settings
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SettingsPatch'
security:
  - SessionCookie: []
components:
  parameters:
    AsOf:
      name: as_of
      in: query
      required: false
      description: Defaults to today.
      schema:
        $ref: '#/components/schemas/Date'
      explode: false
    BusinessPath:
      name: businessID
      in: path
      required: true
      description: The business id, from `GET /bff/me`.
      schema:
        type: string
    Csrf:
      name: X-CSRF-Token
      in: header
      required: true
      description: The value of the `otazio_csrf` cookie. Required on every POST and PATCH.
      schema:
        type: string
    Idempotency:
      name: Idempotency-Key
      in: header
      required: false
      description: |-
        Makes a retry safe: the first response is stored and replayed for the same
        key and body (with `Idempotent-Replayed: true`). At most 200 characters.
      schema:
        type: string
    Paging.cursor:
      name: cursor
      in: query
      required: false
      description: The `next_cursor` of the previous page.
      schema:
        type: string
      explode: false
    Paging.limit:
      name: limit
      in: query
      required: false
      description: Page size, 1 to 200 (larger values are capped).
      schema:
        type: integer
        format: int32
        minimum: 1
        default: 50
      explode: false
    RecordPath.id:
      name: id
      in: path
      required: true
      description: The record id.
      schema:
        $ref: '#/components/schemas/Id'
    Searchable.external_ref:
      name: external_ref
      in: query
      required: false
      description: 'Find by external reference: `<system>:<id>`, e.g. `crm:4711`.'
      schema:
        type: string
      explode: false
    Searchable.q:
      name: q
      in: query
      required: false
      description: Text search.
      schema:
        type: string
      explode: false
    TokenPath:
      name: token
      in: path
      required: true
      description: The link token from the sent email. It identifies the business and the document.
      schema:
        type: string
  schemas:
    ARAging:
      type: object
      required:
        - as_of
        - rows
        - totals
        - unapplied_credit
        - total
        - ar_balance
        - ties
      properties:
        as_of:
          $ref: '#/components/schemas/Date'
        rows:
          type: array
          items:
            $ref: '#/components/schemas/AgingRow'
        totals:
          $ref: '#/components/schemas/AgingBuckets'
        unapplied_credit:
          $ref: '#/components/schemas/Money'
        total:
          $ref: '#/components/schemas/Money'
        ar_balance:
          $ref: '#/components/schemas/Money'
        ties:
          type: boolean
      description: Receivables by age. `ties` is true when the total equals the AR account.
    AccountType:
      type: string
      enum:
        - asset
        - liability
        - equity
        - income
        - expense
    AgingBuckets:
      type: object
      required:
        - current
        - days_1_30
        - days_31_60
        - days_61_90
        - days_over_90
      properties:
        current:
          $ref: '#/components/schemas/Money'
        days_1_30:
          $ref: '#/components/schemas/Money'
        days_31_60:
          $ref: '#/components/schemas/Money'
        days_61_90:
          $ref: '#/components/schemas/Money'
        days_over_90:
          $ref: '#/components/schemas/Money'
    AgingInvoice:
      type: object
      required:
        - document_id
        - number
        - issue_date
        - due_date
        - days_overdue
        - total
        - balance
      properties:
        document_id:
          $ref: '#/components/schemas/Id'
        number:
          type: string
        issue_date:
          $ref: '#/components/schemas/Date'
        due_date:
          $ref: '#/components/schemas/Date'
        days_overdue:
          type: integer
          format: int32
        total:
          $ref: '#/components/schemas/Money'
        balance:
          $ref: '#/components/schemas/Money'
    AgingRow:
      type: object
      required:
        - customer_id
        - customer_name
        - current
        - days_1_30
        - days_31_60
        - days_61_90
        - days_over_90
        - unapplied_credit
        - total
        - invoices
      properties:
        customer_id:
          anyOf:
            - $ref: '#/components/schemas/Id'
            - type: 'null'
        customer_name:
          type: string
        current:
          $ref: '#/components/schemas/Money'
        days_1_30:
          $ref: '#/components/schemas/Money'
        days_31_60:
          $ref: '#/components/schemas/Money'
        days_61_90:
          $ref: '#/components/schemas/Money'
        days_over_90:
          $ref: '#/components/schemas/Money'
        unapplied_credit:
          $ref: '#/components/schemas/Money'
          description: 'Negative: money received and not yet applied.'
        total:
          $ref: '#/components/schemas/Money'
        invoices:
          type: array
          items:
            $ref: '#/components/schemas/AgingInvoice'
    Application:
      type: object
      required:
        - document_id
        - document_number
        - amount
      properties:
        document_id:
          $ref: '#/components/schemas/Id'
        document_number:
          type: string
        amount:
          $ref: '#/components/schemas/Money'
      description: Part of a payment applied to an invoice.
    ApplicationInput:
      type: object
      required:
        - document_id
        - amount
      properties:
        document_id:
          $ref: '#/components/schemas/Id'
          description: An issued invoice of the same customer.
        amount:
          $ref: '#/components/schemas/Money'
    Attachment:
      type: object
      required:
        - key
        - content_type
        - size
        - filename
      properties:
        key:
          type: string
          description: Put this in `attachment_keys` of an expense, or `logo_key` in settings.
        content_type:
          type: string
        size:
          type: integer
          format: int64
        filename:
          type: string
    BalanceSheet:
      type: object
      required:
        - as_of
        - assets
        - liabilities
        - equity
        - total_assets
        - total_liabilities
        - retained_earnings
        - current_year_earnings
        - total_equity
        - total_liabilities_and_equity
        - balanced
      properties:
        as_of:
          $ref: '#/components/schemas/Date'
        assets:
          type: array
          items:
            $ref: '#/components/schemas/ReportRow'
        liabilities:
          type: array
          items:
            $ref: '#/components/schemas/ReportRow'
        equity:
          type: array
          items:
            $ref: '#/components/schemas/ReportRow'
        total_assets:
          $ref: '#/components/schemas/Money'
        total_liabilities:
          $ref: '#/components/schemas/Money'
        retained_earnings:
          $ref: '#/components/schemas/Money'
        current_year_earnings:
          $ref: '#/components/schemas/Money'
        total_equity:
          $ref: '#/components/schemas/Money'
        total_liabilities_and_equity:
          $ref: '#/components/schemas/Money'
        balanced:
          type: boolean
    BusinessCreate:
      type: object
      required:
        - name
      properties:
        name:
          type: string
          description: 1 to 200 characters.
    Category:
      type: object
      required:
        - id
        - code
        - name
        - type
        - normal_balance
        - schedule_c_line
        - locked
        - active
        - created_at
        - updated_at
      properties:
        id:
          $ref: '#/components/schemas/Id'
        code:
          type: string
        name:
          type: string
        type:
          $ref: '#/components/schemas/AccountType'
        normal_balance:
          type: string
          enum:
            - debit
            - credit
        role:
          type: string
          description: Set on accounts the app posts to by role (bank, accounts receivable, ...).
        schedule_c_line:
          type: string
          description: The Schedule C line, e.g. `"22"` for supplies. Empty if none.
        locked:
          type: boolean
        active:
          type: boolean
        created_at:
          $ref: '#/components/schemas/Timestamp'
        updated_at:
          $ref: '#/components/schemas/Timestamp'
      description: |-
        A category: an account in the hidden ledger. Accounts with a
        `role` are used by the app itself and are `locked`.
    CategoryCreate:
      type: object
      required:
        - name
      properties:
        name:
          type: string
        type:
          type: string
          enum:
            - income
            - expense
          default: expense
        code:
          type: string
          description: Account code; assigned if omitted.
        schedule_c_line:
          type: string
        active:
          type: boolean
      description: Fields to create a category.
    CategoryList:
      type: object
      required:
        - items
        - next_cursor
      properties:
        items:
          type: array
          items:
            $ref: '#/components/schemas/Category'
        next_cursor:
          anyOf:
            - type: string
            - type: 'null'
          description: Pass as `?cursor=` for the next page; `null` on the last page.
      description: The list envelope.
    CategoryPatch:
      type: object
      properties:
        name:
          type: string
        schedule_c_line:
          type: string
        active:
          type: boolean
      description: A partial update. `type` and `code` cannot change.
    ConvertInput:
      type: object
      properties:
        issue_date:
          $ref: '#/components/schemas/Date'
          description: Invoice date when a work order becomes an invoice.
    Customer:
      type: object
      required:
        - id
        - name
        - email
        - phone
        - address
        - notes
        - sms_consent
        - external_refs
        - created_at
        - updated_at
      properties:
        id:
          $ref: '#/components/schemas/Id'
        name:
          type: string
        email:
          type: string
        phone:
          type: string
        address:
          type: string
          description: Free-form postal address.
        notes:
          type: string
        sms_consent:
          type: boolean
          description: The customer agreed to text messages.
        external_refs:
          type: array
          items:
            $ref: '#/components/schemas/ExternalRef'
        created_at:
          $ref: '#/components/schemas/Timestamp'
        updated_at:
          $ref: '#/components/schemas/Timestamp'
      description: A customer.
    CustomerCreate:
      type: object
      required:
        - name
      properties:
        name:
          type: string
        email:
          type: string
          description: Must be an email address if set.
        phone:
          type: string
        address:
          type: string
        notes:
          type: string
        sms_consent:
          type: boolean
        external_refs:
          type: array
          items:
            $ref: '#/components/schemas/ExternalRef'
      description: Fields to create a customer.
    CustomerList:
      type: object
      required:
        - items
        - next_cursor
      properties:
        items:
          type: array
          items:
            $ref: '#/components/schemas/Customer'
        next_cursor:
          anyOf:
            - type: string
            - type: 'null'
          description: Pass as `?cursor=` for the next page; `null` on the last page.
      description: The list envelope.
    CustomerPatch:
      type: object
      properties:
        name:
          type: string
        email:
          type: string
          description: Must be an email address if set.
        phone:
          type: string
        address:
          type: string
        notes:
          type: string
        sms_consent:
          type: boolean
        external_refs:
          type: array
          items:
            $ref: '#/components/schemas/ExternalRef'
      description: A partial update. Omitted fields are unchanged; `external_refs` replaces the whole list.
    Date:
      type: string
      format: date
      description: An accounting date, `YYYY-MM-DD`.
      examples:
        - '2026-12-01'
    Decimal:
      type: string
      pattern: ^-?[0-9]+(\.[0-9]{1,4})?$
      description: A non-money decimal (quantity or percent) with up to 4 places, trailing zeros trimmed.
      examples:
        - '1.5'
    Delivery:
      type: object
      required:
        - id
        - document_id
        - channel
        - to
        - subject
        - message
        - provider_id
        - status
        - created_at
      properties:
        id:
          $ref: '#/components/schemas/Id'
        document_id:
          $ref: '#/components/schemas/Id'
        channel:
          type: string
          enum:
            - email
        to:
          type: string
        subject:
          type: string
        message:
          type: string
        provider_id:
          type: string
        status:
          type: string
          enum:
            - sent
            - failed
        error:
          type: string
        created_at:
          $ref: '#/components/schemas/Timestamp'
      description: One send of a document.
    DeliveryList:
      type: object
      required:
        - items
        - next_cursor
      properties:
        items:
          type: array
          items:
            $ref: '#/components/schemas/Delivery'
        next_cursor:
          anyOf:
            - type: string
            - type: 'null'
          description: Pass as `?cursor=` for the next page; `null` on the last page.
      description: The list envelope.
    Document:
      type: object
      required:
        - id
        - kind
        - status
        - number
        - quote_number
        - work_order_number
        - invoice_number
        - customer_id
        - customer_name
        - issue_date
        - due_date
        - terms_days
        - notes
        - lines
        - subtotal
        - taxable_subtotal
        - tax_rate
        - tax
        - total
        - amount_paid
        - balance_due
        - posted
        - approved_at
        - sent_at
        - void_date
        - voided_at
        - created_by_ai
        - external_refs
        - created_at
        - updated_at
      properties:
        id:
          $ref: '#/components/schemas/Id'
        kind:
          $ref: '#/components/schemas/DocumentKind'
        status:
          $ref: '#/components/schemas/DocumentStatus'
        number:
          type: string
          description: The number of the current stage, e.g. `INV-12`.
        quote_number:
          anyOf:
            - type: string
            - type: 'null'
        work_order_number:
          anyOf:
            - type: string
            - type: 'null'
        invoice_number:
          anyOf:
            - type: string
            - type: 'null'
        customer_id:
          anyOf:
            - $ref: '#/components/schemas/Id'
            - type: 'null'
        customer_name:
          type: string
        issue_date:
          $ref: '#/components/schemas/Date'
        due_date:
          anyOf:
            - $ref: '#/components/schemas/Date'
            - type: 'null'
        terms_days:
          type: integer
          format: int32
        notes:
          type: string
        lines:
          type: array
          items:
            $ref: '#/components/schemas/Line'
        subtotal:
          $ref: '#/components/schemas/Money'
        taxable_subtotal:
          $ref: '#/components/schemas/Money'
        tax_rate:
          $ref: '#/components/schemas/Decimal'
          description: Percent.
        tax:
          $ref: '#/components/schemas/Money'
        total:
          $ref: '#/components/schemas/Money'
        amount_paid:
          $ref: '#/components/schemas/Money'
        balance_due:
          $ref: '#/components/schemas/Money'
        posted:
          type: boolean
          description: Whether the document is in the books (issued invoices).
        approved_at:
          anyOf:
            - $ref: '#/components/schemas/Timestamp'
            - type: 'null'
        sent_at:
          anyOf:
            - $ref: '#/components/schemas/Timestamp'
            - type: 'null'
          description: When this stage was last sent; cleared on convert.
        void_date:
          anyOf:
            - $ref: '#/components/schemas/Date'
            - type: 'null'
        voided_at:
          anyOf:
            - $ref: '#/components/schemas/Timestamp'
            - type: 'null'
        void_reason:
          type: string
        created_by_ai:
          type: boolean
          description: Created by an AI assistant on the user's behalf.
        external_refs:
          type: array
          items:
            $ref: '#/components/schemas/ExternalRef'
        created_at:
          $ref: '#/components/schemas/Timestamp'
        updated_at:
          $ref: '#/components/schemas/Timestamp'
      description: A quote, work order or invoice.
    DocumentCreate:
      type: object
      properties:
        kind:
          $ref: '#/components/schemas/DocumentKind'
          description: Defaults to `invoice`.
          default: invoice
        customer_id:
          $ref: '#/components/schemas/Id'
        issue_date:
          $ref: '#/components/schemas/Date'
          description: Defaults to today.
        due_date:
          $ref: '#/components/schemas/Date'
          description: Defaults to issue date plus `terms_days`.
        terms_days:
          type: integer
          format: int32
          description: 0 to 365; defaults to the business's terms.
        notes:
          type: string
        lines:
          type: array
          items:
            $ref: '#/components/schemas/LineInput'
        draft:
          type: boolean
          description: 'Invoice only: save without posting. Issue it later with convert.'
          default: false
        created_by_ai:
          type: boolean
          description: Set when an AI assistant creates the document.
        external_refs:
          type: array
          items:
            $ref: '#/components/schemas/ExternalRef'
      description: Fields to create a document.
    DocumentKind:
      type: string
      enum:
        - quote
        - work_order
        - invoice
      description: Document kinds. One record moves quote, then work order, then invoice.
    DocumentList:
      type: object
      required:
        - items
        - next_cursor
      properties:
        items:
          type: array
          items:
            $ref: '#/components/schemas/Document'
        next_cursor:
          anyOf:
            - type: string
            - type: 'null'
          description: Pass as `?cursor=` for the next page; `null` on the last page.
      description: The list envelope.
    DocumentPatch:
      type: object
      properties:
        customer_id:
          $ref: '#/components/schemas/Id'
        issue_date:
          $ref: '#/components/schemas/Date'
        due_date:
          $ref: '#/components/schemas/Date'
        terms_days:
          type: integer
          format: int32
        notes:
          type: string
        lines:
          type: array
          items:
            $ref: '#/components/schemas/LineInput'
          description: Replaces all lines.
        created_by_ai:
          type: boolean
        external_refs:
          type: array
          items:
            $ref: '#/components/schemas/ExternalRef'
      description: |-
        A partial update. Quotes, work orders and draft invoices are fully
        editable; a posted invoice only takes notes, due date and external refs.
        `kind`, `status` and `draft` change only through actions.
    DocumentStatus:
      type: string
      enum:
        - draft
        - sent
        - approved
        - declined
        - in_progress
        - open
        - partial
        - paid
        - void
      description: Document statuses.
    Expense:
      type: object
      required:
        - id
        - number
        - date
        - vendor_name
        - amount
        - category_id
        - category_name
        - paid_from
        - document_id
        - cost_type
        - memo
        - attachment_keys
        - status
        - void_date
        - voided_at
        - external_refs
        - created_at
        - updated_at
      properties:
        id:
          $ref: '#/components/schemas/Id'
        number:
          type: string
        date:
          $ref: '#/components/schemas/Date'
        vendor_name:
          type: string
        amount:
          $ref: '#/components/schemas/Money'
        category_id:
          $ref: '#/components/schemas/Id'
        category_name:
          type: string
        paid_from:
          $ref: '#/components/schemas/PaidFrom'
        document_id:
          anyOf:
            - $ref: '#/components/schemas/Id'
            - type: 'null'
          description: The job (work order or invoice) this cost belongs to.
        document_number:
          type: string
        cost_type:
          anyOf:
            - type: string
              enum:
                - material
                - labor
                - other
            - type: 'null'
          description: Set on job costs.
        memo:
          type: string
        attachment_keys:
          type: array
          items:
            type: string
          description: Storage keys from `POST /attachments`.
        status:
          type: string
          enum:
            - posted
            - void
        void_date:
          anyOf:
            - $ref: '#/components/schemas/Date'
            - type: 'null'
        voided_at:
          anyOf:
            - $ref: '#/components/schemas/Timestamp'
            - type: 'null'
        external_refs:
          type: array
          items:
            $ref: '#/components/schemas/ExternalRef'
        created_at:
          $ref: '#/components/schemas/Timestamp'
        updated_at:
          $ref: '#/components/schemas/Timestamp'
      description: Money spent.
    ExpenseCreate:
      type: object
      required:
        - amount
        - category_id
      properties:
        date:
          $ref: '#/components/schemas/Date'
          description: Defaults to today.
        vendor_name:
          type: string
        amount:
          $ref: '#/components/schemas/Money'
          description: More than zero.
        category_id:
          $ref: '#/components/schemas/Id'
          description: An active expense category (or owner draws, sales tax payable, the credit card).
        paid_from:
          $ref: '#/components/schemas/PaidFrom'
          default: bank
        document_id:
          $ref: '#/components/schemas/Id'
          description: A work order or invoice that is not void.
        cost_type:
          type: string
          enum:
            - material
            - labor
            - other
            - ''
          description: Job cost type; inferred from the category when omitted. Empty clears it.
        memo:
          type: string
        attachment_keys:
          type: array
          items:
            type: string
        external_refs:
          type: array
          items:
            $ref: '#/components/schemas/ExternalRef'
      description: Fields to record an expense.
    ExpenseList:
      type: object
      required:
        - items
        - next_cursor
      properties:
        items:
          type: array
          items:
            $ref: '#/components/schemas/Expense'
        next_cursor:
          anyOf:
            - type: string
            - type: 'null'
          description: Pass as `?cursor=` for the next page; `null` on the last page.
      description: The list envelope.
    ExpensePatch:
      type: object
      properties:
        date:
          $ref: '#/components/schemas/Date'
          description: Defaults to today.
        vendor_name:
          type: string
        amount:
          $ref: '#/components/schemas/Money'
          description: More than zero.
        category_id:
          $ref: '#/components/schemas/Id'
          description: An active expense category (or owner draws, sales tax payable, the credit card).
        paid_from:
          $ref: '#/components/schemas/PaidFrom'
          default: bank
        document_id:
          $ref: '#/components/schemas/Id'
          description: A work order or invoice that is not void.
        cost_type:
          type: string
          enum:
            - material
            - labor
            - other
            - ''
          description: Job cost type; inferred from the category when omitted. Empty clears it.
        memo:
          type: string
        attachment_keys:
          type: array
          items:
            type: string
        external_refs:
          type: array
          items:
            $ref: '#/components/schemas/ExternalRef'
      description: A partial update. Changing amounts, dates or accounts reposts the expense.
    ExternalRef:
      type: object
      required:
        - system
        - id
      properties:
        system:
          type: string
          description: The other system, e.g. `crm` or `jobber`. Must not contain `:`.
        id:
          type: string
          description: The record's id in that system. Unique per record type and business together with `system`.
        url:
          type: string
          description: A link to the record there (http or https).
        label:
          type: string
          description: A label to show for the link.
      description: A link from this record to the same record in another system.
    FieldError:
      type: object
      required:
        - field
        - message
      properties:
        field:
          type: string
          description: The JSON path of the field, e.g. `lines[0].quantity`.
        message:
          type: string
      description: One invalid field.
    Id:
      type: string
      format: uuid
      description: A record id (UUID).
    Item:
      type: object
      required:
        - id
        - name
        - description
        - kind
        - unit_price
        - taxable
        - category_id
        - active
        - external_refs
        - created_at
        - updated_at
      properties:
        id:
          $ref: '#/components/schemas/Id'
        name:
          type: string
        description:
          type: string
        kind:
          $ref: '#/components/schemas/LineKind'
        unit_price:
          $ref: '#/components/schemas/Money'
        taxable:
          type: boolean
        category_id:
          anyOf:
            - $ref: '#/components/schemas/Id'
            - type: 'null'
          description: Income category the line posts to; `null` uses the default for the kind.
        active:
          type: boolean
        external_refs:
          type: array
          items:
            $ref: '#/components/schemas/ExternalRef'
        created_at:
          $ref: '#/components/schemas/Timestamp'
        updated_at:
          $ref: '#/components/schemas/Timestamp'
      description: A saved item to put on document lines.
    ItemCreate:
      type: object
      required:
        - name
      properties:
        name:
          type: string
        description:
          type: string
        kind:
          $ref: '#/components/schemas/LineKind'
          default: part
        unit_price:
          $ref: '#/components/schemas/Money'
          description: Not negative.
        taxable:
          type: boolean
        category_id:
          $ref: '#/components/schemas/Id'
          description: An income category id.
        active:
          type: boolean
          default: true
        external_refs:
          type: array
          items:
            $ref: '#/components/schemas/ExternalRef'
      description: Fields to create an item.
    ItemList:
      type: object
      required:
        - items
        - next_cursor
      properties:
        items:
          type: array
          items:
            $ref: '#/components/schemas/Item'
        next_cursor:
          anyOf:
            - type: string
            - type: 'null'
          description: Pass as `?cursor=` for the next page; `null` on the last page.
      description: The list envelope.
    ItemPatch:
      type: object
      properties:
        name:
          type: string
        description:
          type: string
        kind:
          $ref: '#/components/schemas/LineKind'
          default: part
        unit_price:
          $ref: '#/components/schemas/Money'
          description: Not negative.
        taxable:
          type: boolean
        category_id:
          $ref: '#/components/schemas/Id'
          description: An income category id.
        active:
          type: boolean
          default: true
        external_refs:
          type: array
          items:
            $ref: '#/components/schemas/ExternalRef'
      description: A partial update.
    JobInProgress:
      type: object
      required:
        - document_id
        - number
        - customer_name
        - issue_date
        - total
      properties:
        document_id:
          $ref: '#/components/schemas/Id'
        number:
          type: string
        customer_name:
          type: string
        issue_date:
          $ref: '#/components/schemas/Date'
        total:
          $ref: '#/components/schemas/Money'
    JobProfit:
      type: object
      required:
        - document_id
        - kind
        - status
        - number
        - customer_name
        - issue_date
        - billed
        - parts_billed
        - labor_billed
        - fees_billed
        - discounts
        - costs
        - material_costs
        - labor_costs
        - other_costs
        - profit
        - parts_margin
        - margin_percent
      properties:
        document_id:
          $ref: '#/components/schemas/Id'
        kind:
          type: string
          enum:
            - work_order
            - invoice
        status:
          type: string
        number:
          type: string
        customer_name:
          type: string
        issue_date:
          $ref: '#/components/schemas/Date'
        billed:
          $ref: '#/components/schemas/Money'
          description: Income excluding sales tax.
        parts_billed:
          $ref: '#/components/schemas/Money'
        labor_billed:
          $ref: '#/components/schemas/Money'
        fees_billed:
          $ref: '#/components/schemas/Money'
        discounts:
          $ref: '#/components/schemas/Money'
        costs:
          $ref: '#/components/schemas/Money'
        material_costs:
          $ref: '#/components/schemas/Money'
        labor_costs:
          $ref: '#/components/schemas/Money'
        other_costs:
          $ref: '#/components/schemas/Money'
        profit:
          $ref: '#/components/schemas/Money'
        parts_margin:
          $ref: '#/components/schemas/Money'
          description: Parts billed minus material costs.
        margin_percent:
          anyOf:
            - $ref: '#/components/schemas/Decimal'
            - type: 'null'
          description: Percent; `null` when nothing was billed.
      description: Profit of one job (work order or invoice).
    JobProfitReport:
      type: object
      required:
        - items
      properties:
        items:
          type: array
          items:
            $ref: '#/components/schemas/JobProfit'
    Journal:
      type: object
      required:
        - from
        - to
        - items
      properties:
        from:
          $ref: '#/components/schemas/Date'
        to:
          $ref: '#/components/schemas/Date'
        items:
          type: array
          items:
            $ref: '#/components/schemas/JournalEntry'
    JournalEntry:
      type: object
      required:
        - id
        - date
        - period
        - source_type
        - source_id
        - memo
        - reverses_id
        - created_by
        - created_at
        - lines
      properties:
        id:
          $ref: '#/components/schemas/Id'
        date:
          $ref: '#/components/schemas/Date'
        period:
          type: string
          description: '`YYYY-MM`.'
        source_type:
          type: string
          description: 'What posted it: `document`, `payment`, `expense`, ...'
        source_id:
          type: string
        memo:
          type: string
        reverses_id:
          anyOf:
            - $ref: '#/components/schemas/Id'
            - type: 'null'
          description: Set on reversals (voids).
        created_by:
          type: string
        created_at:
          $ref: '#/components/schemas/Timestamp'
        lines:
          type: array
          items:
            $ref: '#/components/schemas/JournalLine'
    JournalLine:
      type: object
      required:
        - line_no
        - account_id
        - account_code
        - account_name
        - debit
        - credit
        - memo
        - customer_id
        - document_id
      properties:
        line_no:
          type: integer
          format: int32
        account_id:
          $ref: '#/components/schemas/Id'
        account_code:
          type: string
        account_name:
          type: string
        debit:
          $ref: '#/components/schemas/Money'
        credit:
          $ref: '#/components/schemas/Money'
        memo:
          type: string
        customer_id:
          anyOf:
            - $ref: '#/components/schemas/Id'
            - type: 'null'
        document_id:
          anyOf:
            - $ref: '#/components/schemas/Id'
            - type: 'null'
    Line:
      type: object
      required:
        - id
        - item_id
        - kind
        - description
        - quantity
        - unit_price
        - amount
        - taxable
        - category_id
      properties:
        id:
          $ref: '#/components/schemas/Id'
        item_id:
          anyOf:
            - $ref: '#/components/schemas/Id'
            - type: 'null'
        kind:
          $ref: '#/components/schemas/LineKind'
        description:
          type: string
        quantity:
          $ref: '#/components/schemas/Decimal'
          description: Negative on discount lines.
        unit_price:
          $ref: '#/components/schemas/Money'
        amount:
          $ref: '#/components/schemas/Money'
          description: '`quantity` x `unit_price`, rounded to cents.'
        taxable:
          type: boolean
        category_id:
          anyOf:
            - $ref: '#/components/schemas/Id'
            - type: 'null'
      description: A document line.
    LineInput:
      type: object
      properties:
        item_id:
          $ref: '#/components/schemas/Id'
        kind:
          $ref: '#/components/schemas/LineKind'
          default: part
        description:
          type: string
        quantity:
          $ref: '#/components/schemas/Decimal'
          description: Not zero.
          default: '1'
        unit_price:
          $ref: '#/components/schemas/Money'
          description: Not negative.
        taxable:
          type: boolean
          description: 'Default: parts yes, labor per `tax_labor` in settings, fees and discounts no.'
        category_id:
          $ref: '#/components/schemas/Id'
          description: An income category id to post this line to.
      description: |-
        A line to save. With `item_id`, the item fills kind, description, price
        and taxability; anything you send overrides it. Without, `description` is
        required. A discount takes a positive price and is stored as a negative
        quantity.
    LineKind:
      type: string
      enum:
        - part
        - labor
        - fee
        - discount
      description: Line kinds of items and document lines.
    LogoutResult:
      type: object
      required:
        - logout_url
      properties:
        logout_url:
          type: string
          description: Where to send the browser to end the identity provider session.
    Me:
      type: object
      required:
        - user
        - businesses
      properties:
        user:
          $ref: '#/components/schemas/MeUser'
        businesses:
          type: array
          items:
            $ref: '#/components/schemas/Membership'
      description: The signed-in user and their businesses.
    MeUser:
      type: object
      required:
        - id
        - email
        - name
      properties:
        id:
          type: string
        email:
          type: string
        name:
          type: string
    Membership:
      type: object
      required:
        - id
        - name
        - role
      properties:
        id:
          type: string
          description: Use as `{businessID}` in `/v1/businesses/{businessID}/`.
        name:
          type: string
        role:
          type: string
          enum:
            - owner
            - member
            - accountant
      description: A business the user belongs to.
    Money:
      type: string
      pattern: ^-?[0-9]+\.[0-9]{2}$
      description: 'Money: a decimal string with exactly 2 places. Numbers are accepted on input; never use floats.'
      examples:
        - '125.00'
    PaidFrom:
      type: string
      enum:
        - bank
        - card
        - cash
        - personal
      description: Where the money came from.
    Payment:
      type: object
      required:
        - id
        - number
        - customer_id
        - customer_name
        - date
        - amount
        - method
        - reference
        - memo
        - status
        - applications
        - unapplied
        - void_date
        - voided_at
        - external_refs
        - created_at
        - updated_at
      properties:
        id:
          $ref: '#/components/schemas/Id'
        number:
          type: string
        customer_id:
          anyOf:
            - $ref: '#/components/schemas/Id'
            - type: 'null'
        customer_name:
          type: string
        date:
          $ref: '#/components/schemas/Date'
        amount:
          $ref: '#/components/schemas/Money'
        method:
          $ref: '#/components/schemas/PaymentMethod'
        reference:
          type: string
          description: Check number, transfer reference and so on.
        memo:
          type: string
        status:
          type: string
          enum:
            - posted
            - void
        applications:
          type: array
          items:
            $ref: '#/components/schemas/Application'
        unapplied:
          $ref: '#/components/schemas/Money'
          description: Left as customer credit.
        void_date:
          anyOf:
            - $ref: '#/components/schemas/Date'
            - type: 'null'
        voided_at:
          anyOf:
            - $ref: '#/components/schemas/Timestamp'
            - type: 'null'
        external_refs:
          type: array
          items:
            $ref: '#/components/schemas/ExternalRef'
        created_at:
          $ref: '#/components/schemas/Timestamp'
        updated_at:
          $ref: '#/components/schemas/Timestamp'
      description: Money received.
    PaymentCreate:
      type: object
      required:
        - date
        - amount
        - method
      properties:
        customer_id:
          $ref: '#/components/schemas/Id'
          description: Required if any of the amount is left unapplied.
        date:
          $ref: '#/components/schemas/Date'
          description: The date the money was received; not before the invoices' dates.
        amount:
          $ref: '#/components/schemas/Money'
          description: More than zero.
        method:
          $ref: '#/components/schemas/PaymentMethod'
        reference:
          type: string
        memo:
          type: string
        applications:
          type: array
          items:
            $ref: '#/components/schemas/ApplicationInput'
          description: Must not add up to more than `amount`; the rest is customer credit.
        external_refs:
          type: array
          items:
            $ref: '#/components/schemas/ExternalRef'
      description: Fields to record a payment.
    PaymentList:
      type: object
      required:
        - items
        - next_cursor
      properties:
        items:
          type: array
          items:
            $ref: '#/components/schemas/Payment'
        next_cursor:
          anyOf:
            - type: string
            - type: 'null'
          description: Pass as `?cursor=` for the next page; `null` on the last page.
      description: The list envelope.
    PaymentMethod:
      type: string
      enum:
        - cash
        - check
        - card
        - transfer
        - other
    Problem:
      type: object
      required:
        - type
        - title
        - status
      properties:
        type:
          $ref: '#/components/schemas/ProblemType'
        title:
          type: string
          description: A short summary of the type.
        status:
          type: integer
          format: int32
        detail:
          type: string
          description: What went wrong, for a person.
        errors:
          type: array
          items:
            $ref: '#/components/schemas/FieldError'
        existing_id:
          $ref: '#/components/schemas/Id'
          description: 'On `duplicate-external-ref`: the record that already holds the reference.'
      description: An RFC 9457 problem document.
    ProblemType:
      anyOf:
        - type: string
          enum:
            - validation
            - unbalanced
            - period-locked
            - not-found
            - conflict
            - duplicate-external-ref
            - immutable
            - upstream
            - internal
            - unauthenticated
            - csrf-failed
            - permission-denied
            - tenant-unavailable
            - login-failed
            - invalid-request
            - validation-failed
        - type: string
      description: The problem `type`. Each maps to one HTTP status.
    ProfitAndLoss:
      type: object
      required:
        - from
        - to
        - income
        - expenses
        - total_income
        - total_expenses
        - net_income
      properties:
        from:
          $ref: '#/components/schemas/Date'
        to:
          $ref: '#/components/schemas/Date'
        income:
          type: array
          items:
            $ref: '#/components/schemas/ReportRow'
        expenses:
          type: array
          items:
            $ref: '#/components/schemas/ReportRow'
        total_income:
          $ref: '#/components/schemas/Money'
        total_expenses:
          $ref: '#/components/schemas/Money'
        net_income:
          $ref: '#/components/schemas/Money'
    PublicApproval:
      type: object
      required:
        - status
        - approved_at
      properties:
        status:
          type: string
          enum:
            - approved
        approved_at:
          anyOf:
            - $ref: '#/components/schemas/Timestamp'
            - type: 'null'
    ReportRow:
      type: object
      required:
        - account_id
        - code
        - name
        - amount
      properties:
        account_id:
          $ref: '#/components/schemas/Id'
        code:
          type: string
        name:
          type: string
        schedule_c_line:
          type: string
        amount:
          $ref: '#/components/schemas/Money'
      description: One account's amount on a report.
    Sale:
      type: object
      required:
        - document
        - payment
      properties:
        document:
          $ref: '#/components/schemas/Document'
        payment:
          $ref: '#/components/schemas/Payment'
      description: The invoice and the payment a sale creates.
    SaleCreate:
      type: object
      required:
        - lines
        - method
      properties:
        customer_id:
          $ref: '#/components/schemas/Id'
        date:
          $ref: '#/components/schemas/Date'
          description: Defaults to today.
        lines:
          type: array
          items:
            $ref: '#/components/schemas/LineInput'
          description: At least one; the total must be more than zero.
        method:
          $ref: '#/components/schemas/PaymentMethod'
        reference:
          type: string
        notes:
          type: string
        external_refs:
          type: array
          items:
            $ref: '#/components/schemas/ExternalRef'
      description: A sale paid on the spot ("Got paid" without an invoice).
    ScheduleC:
      type: object
      required:
        - year
        - basis
        - lines
        - gross_receipts
        - gross_income
        - total_expenses
        - net_profit
      properties:
        year:
          type: integer
          format: int32
        basis:
          type: string
          enum:
            - cash
            - accrual
        lines:
          type: array
          items:
            $ref: '#/components/schemas/ScheduleCLine'
        gross_receipts:
          $ref: '#/components/schemas/Money'
          description: Line 1.
        gross_income:
          $ref: '#/components/schemas/Money'
          description: Line 7.
        total_expenses:
          $ref: '#/components/schemas/Money'
          description: Line 28.
        net_profit:
          $ref: '#/components/schemas/Money'
          description: Line 31.
      description: IRS Schedule C (Form 1040) lines for one calendar year.
    ScheduleCLine:
      type: object
      required:
        - line
        - label
        - amount
      properties:
        line:
          type: string
          description: Schedule C line number, e.g. `"1"`, `"22"`.
        label:
          type: string
        amount:
          $ref: '#/components/schemas/Money'
    SendInput:
      type: object
      properties:
        channel:
          type: string
          enum:
            - email
          description: Only `email` today.
          default: email
        to:
          type: string
          description: Defaults to the customer's email.
        message:
          type: string
          description: A note added to the email.
    SendResult:
      type: object
      required:
        - document
        - delivery
        - public_url
      properties:
        document:
          $ref: '#/components/schemas/Document'
        delivery:
          $ref: '#/components/schemas/Delivery'
        public_url:
          type: string
          format: uri
          description: The customer's link to view (and approve) the document.
    Sequence:
      type: object
      required:
        - prefix
        - next
      properties:
        prefix:
          type: string
        next:
          type: integer
          format: int64
      description: 'A number series: the next number is `prefix` + `next`.'
    SequencePatch:
      type: object
      properties:
        prefix:
          type: string
        next:
          type: integer
          format: int64
          minimum: 1
    Settings:
      type: object
      required:
        - business_id
        - name
        - address
        - phone
        - email
        - logo_key
        - invoice_footer
        - default_terms_days
        - sales_tax_enabled
        - sales_tax_rate
        - tax_labor
        - lock_date
        - chart_template
        - next_numbers
        - updated_at
      properties:
        business_id:
          type: string
        name:
          type: string
        address:
          type: string
        phone:
          type: string
        email:
          type: string
        logo_key:
          type: string
          description: Storage key of the logo (from `POST /attachments`).
        invoice_footer:
          type: string
          description: Printed at the bottom of quotes and invoices.
        default_terms_days:
          type: integer
          format: int32
          description: Payment terms for new invoices, 0 to 365.
        sales_tax_enabled:
          type: boolean
        sales_tax_rate:
          $ref: '#/components/schemas/Decimal'
          description: Percent, e.g. `"8.25"`.
        tax_labor:
          type: boolean
          description: Whether labor lines are taxable by default.
        lock_date:
          anyOf:
            - $ref: '#/components/schemas/Date'
            - type: 'null'
          description: Nothing on or before this date can be posted or changed.
        chart_template:
          type: string
        next_numbers:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/Sequence'
          description: 'Keyed by series: `quote`, `work_order`, `invoice`, `payment`, `expense`.'
        updated_at:
          $ref: '#/components/schemas/Timestamp'
      description: Business settings.
    SettingsPatch:
      type: object
      properties:
        name:
          type: string
        address:
          type: string
        phone:
          type: string
        email:
          type: string
        logo_key:
          type: string
        invoice_footer:
          type: string
        default_terms_days:
          type: integer
          format: int32
          minimum: 0
          maximum: 365
        sales_tax_enabled:
          type: boolean
        sales_tax_rate:
          $ref: '#/components/schemas/Decimal'
          description: Percent between 0 and 30.
        tax_labor:
          type: boolean
        lock_date:
          type: string
          description: An empty string clears the lock date.
        next_numbers:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/SequencePatch'
      description: A partial update of settings. Omitted fields are unchanged.
    Summary:
      type: object
      required:
        - as_of
        - month_start
        - revenue_this_month
        - expenses_this_month
        - net_income_this_month
        - accounts_receivable
        - accounts_payable
        - sales_tax_payable
        - cash
        - jobs_in_progress_count
        - jobs_in_progress
      properties:
        as_of:
          $ref: '#/components/schemas/Date'
        month_start:
          $ref: '#/components/schemas/Date'
        revenue_this_month:
          $ref: '#/components/schemas/Money'
        expenses_this_month:
          $ref: '#/components/schemas/Money'
        net_income_this_month:
          $ref: '#/components/schemas/Money'
          description: '"Made this month".'
        accounts_receivable:
          $ref: '#/components/schemas/Money'
          description: '"Owed to you".'
        accounts_payable:
          $ref: '#/components/schemas/Money'
          description: '"You owe": bills plus the credit card.'
        sales_tax_payable:
          $ref: '#/components/schemas/Money'
        cash:
          $ref: '#/components/schemas/Money'
          description: Bank plus cash on hand.
        jobs_in_progress_count:
          type: integer
          format: int32
        jobs_in_progress:
          type: array
          items:
            $ref: '#/components/schemas/JobInProgress'
      description: The home screen numbers.
    Timestamp:
      type: string
      format: date-time
      description: A UTC timestamp, RFC 3339 with milliseconds.
      examples:
        - '2026-12-01T14:03:22.120Z'
    TrialBalance:
      type: object
      required:
        - as_of
        - rows
        - total_debit
        - total_credit
        - balanced
      properties:
        as_of:
          $ref: '#/components/schemas/Date'
        rows:
          type: array
          items:
            $ref: '#/components/schemas/TrialBalanceRow'
        total_debit:
          $ref: '#/components/schemas/Money'
        total_credit:
          $ref: '#/components/schemas/Money'
        balanced:
          type: boolean
    TrialBalanceRow:
      type: object
      required:
        - account_id
        - code
        - name
        - type
        - debit
        - credit
      properties:
        account_id:
          $ref: '#/components/schemas/Id'
        code:
          type: string
        name:
          type: string
        type:
          $ref: '#/components/schemas/AccountType'
        debit:
          $ref: '#/components/schemas/Money'
        credit:
          $ref: '#/components/schemas/Money'
    UploadForm:
      type: object
      properties:
        file:
          description: An image (JPEG, PNG, GIF, WebP, HEIC) or a PDF, at most 10 MB.
      required:
        - file
    VoidDateInput:
      type: object
      properties:
        date:
          $ref: '#/components/schemas/Date'
          description: Date of the reversal; defaults to the original date.
    VoidDocumentInput:
      type: object
      properties:
        date:
          $ref: '#/components/schemas/Date'
          description: Date of the reversal; defaults to the document date.
        reason:
          type: string
  securitySchemes:
    SessionCookie:
      type: apiKey
      in: cookie
      name: otazio_session
      description: The session cookie set by `/bff/login`. Mutating requests also need `X-CSRF-Token`.
servers:
  - url: '{server}'
    description: Production (planned, available at launch)
    variables:
      server:
        default: https://api.otazio.com
