> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lerian.studio/llms.txt
> Use this file to discover all available pages before exploring further.

# Preflight the accounting routes of a ledger

> Reports whether the plugin can post against one (organization, ledger) of the caller's tenant, and the state of each canonical flow there: BOLETO_IN, PAYMENT_OUT and DARF_OUT, each complete, absent, incomplete (with the missing route codes), ambiguous (with the repeated codes) or malformed (with the code and the reason).

The routes reported are the ORGANIZATION's: from Midaz v4.1.0 on, a listing through any ledger of the organization returns every route of it, so two ledgers of one organization report the same flows. `validateRoutes` and `ready` are the requested ledger's.

READ-ONLY. It reads the ledger live, with GET requests only, and bypasses the accounting routes cache: nothing is posted, cached or stored, so it is safe to run right after provisioning and as often as needed.

`ready` is the verdict on the WHOLE ledger: a flow reported complete in a ledger that is not ready still does not post. `reason` names the class of the verdict: accounting_routes_not_provisioned (ready: no canonical route, and the ledger does not validate routes), accounting_routes_required_but_absent, accounting_routes_incomplete, accounting_routes_ambiguous, accounting_routes_malformed, accounting_routes_dependency_unavailable, accounting_routes_access_denied or accounting_routes_unreadable. It is absent for a ledger that holds every canonical route.

The ACCOUNTING_ROUTES_ENABLED knob is REPORTED, NOT OBEYED: the verdict is judged as if it were on, because this is what runs before it is turned on, and its current value is in `accountingRoutesEnabled`.

The organization comes from the X-Organization-Id header (400 PBP-0025) and the ledger from the ledgerId query parameter (400 PBP-0026). An organization or ledger the ledger does not know, for this tenant, is answered 404 without saying which.



## OpenAPI

````yaml /en/openapi/v3-current/payments.yaml get /v1/admin/accounting-routes/preflight
openapi: 3.1.0
info:
  description: >-
    API for the Lerian Payments interface via BTG. It covers boleto issuance,
    cancellation, and queries; bill payments (bankslip, utilities, and DARF) and
    queries; aggregated boleto and payment dashboards; provider connection and
    outbound webhook configuration; and the provider webhook receiver for
    settlement events.


    ERROR BODIES. A failed request arrives in one of two shapes, and which one
    you get depends on where the service catches the failure. A failure that the
    request pipeline catches before the API layer sees it answers a flat JSON
    body on application/json; the idempotency check is the pipeline rule you
    meet most often. Authentication and authorization refusals follow the
    response contract documented by the operation. Everything the API layer
    catches answers an RFC 9457 problem document on application/problem+json.
    Read the media type to tell the two apart. Branch on the code member. A
    license refusal carries an LCS code, listed in the License Manager error
    list.
  title: Payments — via BTG API
  version: 1.0.0
servers:
  - url: https://api.example.com
    description: >-
      Replace the example host with the URL provided during environment
      onboarding.
security: []
tags:
  - description: >-
      Tenant-level setup: connecting the banking provider and configuring where
      status notifications are delivered.
    name: Admin
  - description: Issuing, querying and cancelling boletos, and retrieving the rendered PDF.
    name: Boletos
  - description: >-
      Aggregated counts, amounts and breakdowns over a period, for boletos and
      for payments.
    name: Dashboards
  - description: >-
      Paying bankslips, utility bills and DARF tax slips, and querying those
      payments.
    name: Payments
  - description: >-
      The webhook the payment provider posts settlement events to. Authenticated
      with a credential agreed with the provider, not with the platform identity
      used by the rest of this API.
    name: Settlement
paths:
  /v1/admin/accounting-routes/preflight:
    get:
      tags:
        - Admin
      summary: Preflight the accounting routes of a ledger
      description: >-
        Reports whether the plugin can post against one (organization, ledger)
        of the caller's tenant, and the state of each canonical flow there:
        BOLETO_IN, PAYMENT_OUT and DARF_OUT, each complete, absent, incomplete
        (with the missing route codes), ambiguous (with the repeated codes) or
        malformed (with the code and the reason).


        The routes reported are the ORGANIZATION's: from Midaz v4.1.0 on, a
        listing through any ledger of the organization returns every route of
        it, so two ledgers of one organization report the same flows.
        `validateRoutes` and `ready` are the requested ledger's.


        READ-ONLY. It reads the ledger live, with GET requests only, and
        bypasses the accounting routes cache: nothing is posted, cached or
        stored, so it is safe to run right after provisioning and as often as
        needed.


        `ready` is the verdict on the WHOLE ledger: a flow reported complete in
        a ledger that is not ready still does not post. `reason` names the class
        of the verdict: accounting_routes_not_provisioned (ready: no canonical
        route, and the ledger does not validate routes),
        accounting_routes_required_but_absent, accounting_routes_incomplete,
        accounting_routes_ambiguous, accounting_routes_malformed,
        accounting_routes_dependency_unavailable,
        accounting_routes_access_denied or accounting_routes_unreadable. It is
        absent for a ledger that holds every canonical route.


        The ACCOUNTING_ROUTES_ENABLED knob is REPORTED, NOT OBEYED: the verdict
        is judged as if it were on, because this is what runs before it is
        turned on, and its current value is in `accountingRoutesEnabled`.


        The organization comes from the X-Organization-Id header (400 PBP-0025)
        and the ledger from the ledgerId query parameter (400 PBP-0026). An
        organization or ledger the ledger does not know, for this tenant, is
        answered 404 without saying which.
      operationId: preflightAccountingRoutes
      parameters:
        - description: >-
            Midaz organization of the ledger to inspect. Required: a request
            without it, or with a value that is not a canonical UUID, is refused
            with 400 PBP-0025.
          in: header
          name: X-Organization-Id
          schema:
            description: >-
              Midaz organization of the ledger to inspect. Required: a request
              without it, or with a value that is not a canonical UUID, is
              refused with 400 PBP-0025.
            type: string
        - description: >-
            Midaz ledger to inspect. Required: absent, blank or not a canonical
            UUID is refused with 400 PBP-0026.
          explode: false
          in: query
          name: ledgerId
          schema:
            description: >-
              Midaz ledger to inspect. Required: absent, blank or not a
              canonical UUID is refused with 400 PBP-0026.
            type: string
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PreflightAccountingRoutesResponse'
          description: OK
        '400':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
          description: Bad Request
        '401':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
            text/plain:
              schema:
                type: string
          description: >-
            Authentication failed: the request carries no valid credential, or
            the credential does not identify a tenant. The error body is either
            `application/json` with error code `PBP-0003` or
            `application/problem+json` (RFC 9457); read the `Content-Type` to
            parse it. The `text/plain` media type listed for this status is not
            returned. Obtain a valid bearer token and send the request again.
        '403':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
            text/plain:
              schema:
                type: string
          description: >-
            The authenticated principal is not allowed to perform this request.
            The error body is `application/json` with error code `PBP-0004`: the
            principal lacks permission for this operation, and the permission
            has to be granted before the request can succeed. The `text/plain`
            media type listed for this status is not returned.
        '404':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
          description: Not Found
        '422':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
          description: Unprocessable Entity
        '500':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
          description: Internal Server Error
        '503':
          description: >-
            Service Unavailable. PBP-0008 means the tenant's storage could not
            be resolved. The request was not processed.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
      security:
        - BearerAuth: []
components:
  schemas:
    PreflightAccountingRoutesResponse:
      additionalProperties: false
      properties:
        accountingRoutesEnabled:
          description: >-
            Whether ACCOUNTING_ROUTES_ENABLED is on in this deployment.
            Reported, not obeyed: the verdict is judged as if it were on.
          type: boolean
        flows:
          description: >-
            One entry per canonical flow, in the order BOLETO_IN, PAYMENT_OUT,
            DARF_OUT. Empty when the route inventory could not be read.
          items:
            $ref: '#/components/schemas/PreflightAccountingFlowResponse'
          type: array
        ledgerId:
          description: Ledger the preflight read, in canonical form.
          type: string
        organizationId:
          description: Organization the preflight read, in canonical form.
          type: string
        ready:
          description: >-
            Whether the plugin can post against this ledger as far as accounting
            routes are concerned. It is the verdict on the whole ledger: a
            complete flow in a ledger that is not ready does not post.
          type: boolean
        reason:
          description: >-
            Class of the verdict, from a closed vocabulary of
            accounting_routes_* reasons. Absent for a ledger that holds every
            canonical route.
          type: string
        unrecognisedMarkers:
          description: Ledger routes carrying a plugin marker the contract does not know.
          format: int64
          type: integer
        validateRoutes:
          description: >-
            The ledger's validateRoutes setting, or null when the settings could
            not be read.
          type:
            - boolean
            - 'null'
      required:
        - organizationId
        - ledgerId
        - accountingRoutesEnabled
        - ready
        - validateRoutes
        - unrecognisedMarkers
        - flows
      type: object
    Detail:
      additionalProperties: true
      properties:
        code:
          description: >-
            Stable, machine-readable domain error code scoped to the emitting
            service (format: <SERVICE>-NNNN).
          type: string
        detail:
          description: >-
            A human-readable explanation specific to this occurrence of the
            problem.
          examples:
            - Property foo is required but is missing.
          type: string
        errors:
          description: Optional list of individual error details
          items:
            $ref: '#/components/schemas/ErrorDetail'
          type:
            - array
            - 'null'
        instance:
          description: >-
            A URI reference that identifies the specific occurrence of the
            problem.
          examples:
            - https://example.com/error-log/abc123
          format: uri
          type: string
        status:
          description: HTTP status code
          examples:
            - 400
          format: int64
          type: integer
        title:
          description: >-
            A short, human-readable summary of the problem type. This value
            should not change between occurrences of the error.
          examples:
            - Bad Request
          type: string
        type:
          default: about:blank
          description: A URI reference to human-readable documentation for the error.
          examples:
            - https://example.com/errors/example
          format: uri
          type: string
        upstream:
          $ref: '#/components/schemas/Upstream'
          description: >-
            RFC 9457 extension member: the error a proxied third-party provider
            reported. Absent unless the emitting service explicitly surfaced
            one.
      type: object
    ErrorResponse:
      additionalProperties: false
      properties:
        code:
          type: string
        details:
          additionalProperties: {}
          type: object
        message:
          type: string
        title:
          type: string
      required:
        - code
        - title
        - message
      type: object
    PreflightAccountingFlowResponse:
      additionalProperties: false
      properties:
        ambiguousRoutes:
          description: >-
            Route codes of the flow carried by more than one ledger route, when
            the flow is ambiguous.
          items:
            type: string
          type: array
        flow:
          description: Canonical flow code.
          examples:
            - BOLETO_IN
          type: string
        malformedReason:
          description: Which part of that route diverges, when the flow is malformed.
          type: string
        malformedRoute:
          description: >-
            First route code of the flow that diverges from the contract, when
            the flow is malformed.
          type: string
        missingActions:
          description: >-
            Actions the malformed route does not declare, when the reason is
            action_coverage.
          items:
            type: string
          type: array
        missingRoutes:
          description: >-
            Route codes of the flow absent from the ledger, when the flow is
            incomplete.
          items:
            type: string
          type: array
        status:
          description: complete, absent, incomplete, ambiguous or malformed.
          examples:
            - complete
          type: string
      required:
        - flow
        - status
        - missingRoutes
        - ambiguousRoutes
        - missingActions
      type: object
    ErrorDetail:
      additionalProperties: false
      properties:
        location:
          description: >-
            Where the error occurred, e.g. 'body.items[3].tags' or
            'path.thing-id'
          type: string
        message:
          description: Error message text
          type: string
        value:
          description: The value at the given location
      type: object
    Upstream:
      additionalProperties: false
      properties:
        code:
          description: The upstream provider's own error code, verbatim.
          examples:
            - E4001
          type: string
        message:
          description: >-
            The upstream provider's own error message, verbatim (bounded, never
            its raw response body).
          examples:
            - account not found at provider
          type: string
      type: object
  securitySchemes:
    BearerAuth:
      bearerFormat: JWT
      description: JWT bearer token issued by the identity provider.
      scheme: bearer
      type: http

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.