> ## 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.

# Export the discovered accounting routes as a tenant policy document

> Builds the routing.organizations document that makes one organization of the caller's tenant post with the accounting routes discovered in the ledger today, merged into the document the tenant has stored: every other organization is kept as stored, and this organization's entry is replaced or appended.

A complete organization becomes an enabled entry naming, for BOLETO_IN, PAYMENT_OUT and DARF_OUT, the transaction route and the two operation routes, and the counterparty alias when it is not the default @external/BRL, and listing in ledgers this ledger plus the ledgers already stored for the organization: only listed ledgers post with the routes, so export once per ledger that must. An organization with no canonical route becomes a disabled entry (accountingRoutesEnabled false). A discovery that refuses the ledger (incomplete, ambiguous, malformed, unavailable, access denied, unreadable) answers exportable false with the reason and no document.

READ-ONLY. Nothing is written: the operator reviews the answer and writes it with PUT /tenant-system/tenant_policy/routing.organizations, body {"value": <document>}, under tenant-policy x configure. The PUT replaces the whole document and has no concurrency check, so one operator at a time.

The response carries route ids, the same ones GET /tenant-system/tenant_policy/routing.organizations shows, and is guarded by the same tenant-policy x read.

The organization comes from the X-Organization-Id header (400 PBP-0025) and the ledger the route listing goes through from the ledgerId query parameter (400 PBP-0026). A stored document that cannot be read is 503 PBP-0008: exporting without it would drop the other organizations.



## OpenAPI

````yaml /es/openapi/v3-current/payments-pcr.yaml get /v1/admin/accounting-routes/document-export
openapi: 3.1.0
info:
  description: >-
    API for the Lerian Payments interface. It covers boleto issuance,
    cancellation, and queries; boleto collections; CNAB 240 files; aggregated
    boleto and payment dashboards; and provider connection and outbound webhook
    configuration.


    ERROR BODIES. A failed request arrives as an RFC 9457 problem document on
    application/problem+json. Branch on the code member. A license refusal
    carries an LCS code, listed in the License Manager error list.


    NOTICES. The webhooks section describes each notice Payments posts to the
    tenant's callback URL. Delivery does not guarantee order: order a boleto's
    notices by the occurredAt member of the body. Notices of one boleto recorded
    together never tie and follow the order of the facts; notices recorded at
    different moments can tie, and in a tie the boleto query tells the current
    state. The same notice can arrive more than once: after verifying its
    signature and its X-Webhook-Timestamp, discard repetitions by the eventId
    member of the body, equal to the X-Webhook-Id header and the same on every
    attempt.
  title: Payments PCR 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: >-
      CNAB agreements: the link between a Lerian-provider collections agreement
      and the CNAB 240 Lerian files of one account, with its remittance and
      return sequence numbers (NSA) and its return cut times. Every operation of
      this section answers 422 PBP-0900 to a tenant without CNAB 240 enabled.
    name: CNAB Agreements
  - description: >-
      CNAB remittances: the CNAB 240 Lerian remittance files of an organization,
      each received whole, validated and stored encrypted, its title lines
      executed afterwards. A file already received is answered with its stored
      receipt; a new one answers 422 PBP-0900 to a tenant without CNAB 240
      enabled.
    name: CNAB Remittances
  - description: >-
      CNAB returns: the CNAB 240 Lerian return files of an organization, each
      cut from the movement journal of one agreement, at its cut times or on
      demand, with its own consecutive NSA, and the download of the file itself,
      rebuilt from the journal after the stored file is purged. Only the file
      carries personal data. Every operation of this section answers 422
      PBP-0900 to a tenant without CNAB 240 enabled.
    name: CNAB Returns
  - description: >-
      Boleto collections agreements and their reconciliation with the
      beneficiary base of the PCR: the consumption of each beneficiary inventory
      the PCR publishes and the divergences it raises, which carry only
      agreement and situation attributes, never a document or a name. Every
      operation of this section answers 422 PBP-0830 to a tenant without
      collections enabled.
    name: Collections Agreements
  - description: >-
      Boleto collections audit trail: every operation and configuration action,
      append-only, with its author, instant, reason, evidence and the module's
      fields before and after it. Every operation of this section answers 422
      PBP-0830 to a tenant without collections enabled.
    name: Collections Audit
  - description: >-
      Boleto collections beneficiaries: the enablement of the tenant's accounts
      for collections, in batches of up to 5,000 accounts, and the progress and
      per-item outcome of the enablement and bulk adoption batches. Every
      operation of this section answers 422 PBP-0830 to a tenant without
      collections enabled.
    name: Collections Beneficiaries
  - description: >-
      Boleto collections credit entries: what the credit of each write-off moves
      in the ledger, one entry per write-off and phase, the RELEASE to the
      available balance of the title's account and the CHARGEBACK of a write-off
      cancelled after its release, with where each entry stands with the ledger
      and, when it is not posted, why, as a closed code and never the ledger's
      own text. Every operation of this section answers 422 PBP-0830 to a tenant
      without collections enabled.
    name: Collections Credit Entries
  - description: >-
      Boleto collections operation queues: each case that waits for an operator
      and already has its state in collections, with its reason, since when it
      waits and the operations that act on it, read over the states collections
      keeps rather than from a list of its own. Each queue counts the items
      whose age reached its age limit, a per-tenant operational parameter. Every
      operation of this section answers 422 PBP-0830 to a tenant without
      collections enabled.
    name: Collections Operation Queues
  - description: >-
      Boleto collections commands to the PCR: each registration, change and
      write-off sent to the PCR of the institution, with the idempotency key it
      keeps across attempts, its attempts, its next attempt and the last answer
      that did not accept it, never the body sent. Every operation of this
      section answers 422 PBP-0830 to a tenant without collections enabled.
    name: Collections PCR Commands
  - description: >-
      Boleto collections notice subscription of the tenant's connection to the
      PCR: its synchronization with the PCR, the rotation of the secret the PCR
      signs the notices with, the deliveries of notices the PCR recorded for it,
      and the redelivery of a notice whose delivery failed. Every operation of
      this section answers 422 PBP-0830 to a tenant without collections enabled.
    name: Collections PCR Connection
  - description: >-
      Boleto collections notices received from the PCR: each event the PCR of
      the institution delivered to collections, stored once per connection and
      event, with where its processing stands and what it was matched with,
      never the body received. Every operation of this section answers 422
      PBP-0830 to a tenant without collections enabled.
    name: Collections PCR Notices
  - description: >-
      Boleto collections pooled accounts: the links of accounts that issue under
      the agreement of a pooled account, whose holder stays the beneficiary
      while the account's holder is the final one. A link registers nothing at
      Núclea. Every operation of this section answers 422 PBP-0830 to a tenant
      without collections enabled.
    name: Collections Pooled Accounts
  - description: >-
      Boleto collections setup: the tenant's business settings, with the default
      agreement template, the automatic enablement and the retention periods,
      and the tenant's connection to the PCR of its institution. Every operation
      of this section answers 422 PBP-0830 to a tenant without collections
      enabled.
    name: Collections Settings
  - description: >-
      Boleto collections titles: each boleto collections issues at the PCR of
      the institution, with its four state axes (registration, situation at the
      base, credit and block), never the data of a payer or of a beneficiary.
      The barcode and the digitable line are answered only while the title is
      REGISTERED. Every operation of this section answers 422 PBP-0830 to a
      tenant without collections enabled.
    name: Collections Titles
  - description: >-
      Boleto collections write-offs: each write-off of a collections title the
      PCR of the institution notified, with its route, its settlement, the state
      of its credit, its hold and its cancellation deadline, never the data of a
      payer. Every operation of this section answers 422 PBP-0830 to a tenant
      without collections enabled.
    name: Collections Write-offs
  - description: >-
      Aggregated counts, amounts and breakdowns over a period, for boletos and
      for payments.
    name: Dashboards
  - description: >-
      The notices Payments posts to the tenant's callback URL, one per type
      enabled in enabledEvents, each signed with the configuration's secret.
      Each item describes the body, the delivery headers, when the notice is
      sent and which providers send it.
    name: Notices
  - description: >-
      Paying bankslips, utility bills and DARF tax slips, and querying those
      payments.
    name: Payments
paths:
  /v1/admin/accounting-routes/document-export:
    get:
      tags:
        - Admin
      summary: Export the discovered accounting routes as a tenant policy document
      description: >-
        Builds the routing.organizations document that makes one organization of
        the caller's tenant post with the accounting routes discovered in the
        ledger today, merged into the document the tenant has stored: every
        other organization is kept as stored, and this organization's entry is
        replaced or appended.


        A complete organization becomes an enabled entry naming, for BOLETO_IN,
        PAYMENT_OUT and DARF_OUT, the transaction route and the two operation
        routes, and the counterparty alias when it is not the default
        @external/BRL, and listing in ledgers this ledger plus the ledgers
        already stored for the organization: only listed ledgers post with the
        routes, so export once per ledger that must. An organization with no
        canonical route becomes a disabled entry (accountingRoutesEnabled
        false). A discovery that refuses the ledger (incomplete, ambiguous,
        malformed, unavailable, access denied, unreadable) answers exportable
        false with the reason and no document.


        READ-ONLY. Nothing is written: the operator reviews the answer and
        writes it with PUT /tenant-system/tenant_policy/routing.organizations,
        body {"value": <document>}, under tenant-policy x configure. The PUT
        replaces the whole document and has no concurrency check, so one
        operator at a time.


        The response carries route ids, the same ones GET
        /tenant-system/tenant_policy/routing.organizations shows, and is guarded
        by the same tenant-policy x read.


        The organization comes from the X-Organization-Id header (400 PBP-0025)
        and the ledger the route listing goes through from the ledgerId query
        parameter (400 PBP-0026). A stored document that cannot be read is 503
        PBP-0008: exporting without it would drop the other organizations.
      operationId: exportAccountingRoutesDocument
      parameters:
        - description: >-
            Midaz organization to export. 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 to export. Required: a request without it, or
              with a value that is not a canonical UUID, is refused with 400
              PBP-0025.
            type: string
        - description: >-
            A Midaz ledger of the organization, the one the route listing goes
            through. Required: absent, blank or not a canonical UUID is refused
            with 400 PBP-0026.
          explode: false
          in: query
          name: ledgerId
          schema:
            description: >-
              A Midaz ledger of the organization, the one the route listing goes
              through. 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/ExportAccountingRoutesDocumentResponse'
          description: OK
        '400':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
          description: Bad Request
        '401':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
          description: >-
            Authentication failed: the request carries no valid credential, or
            the credential does not identify a tenant. The error body is an RFC
            9457 problem document (`application/problem+json`) with error code
            `PBP-0003`. Obtain a valid bearer token and send the request again.
        '403':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
          description: >-
            The authenticated principal is not allowed to perform this request.
            The error body is an RFC 9457 problem document
            (`application/problem+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.
        '422':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
          description: Unprocessable Entity
        '500':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
          description: Internal Server Error
        '503':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
          description: >-
            Service Unavailable. PBP-0008 means a dependency the request needs,
            authentication or the tenant's storage, is temporarily unavailable.
            The request was not processed; wait and send it again.
      security:
        - BearerAuth: []
components:
  schemas:
    ExportAccountingRoutesDocumentResponse:
      additionalProperties: false
      properties:
        discovered:
          description: >-
            What the discovery found for the organization: complete (every
            canonical route; the entry is enabled with the three flows, and its
            ledgers list this ledger plus the ones already stored for the
            organization), not_provisioned (no canonical route; the entry is
            disabled and lists no ledger) or the accounting_routes_* reason of
            its refusal.
          examples:
            - complete
          type: string
        document:
          additionalProperties: {}
          description: >-
            The routing.organizations document to write: the stored
            organizations unchanged, with this organization's entry replaced or
            appended. It has passed the same parser the write goes through. Send
            it as {"value": <document>} to PUT
            /tenant-system/tenant_policy/routing.organizations. Absent when
            exportable is false.
          type: object
        exportable:
          description: Whether document is present and can be written as it is.
          type: boolean
        ledgerId:
          description: Ledger the route listing went through, in canonical form.
          type: string
        organizationId:
          description: >-
            Organization exported, in the lowercase canonical form the document
            keys it by.
          type: string
        reason:
          description: >-
            Why exportable is false: an accounting_routes_* reason of the
            discovery (accounting_routes_incomplete,
            accounting_routes_ambiguous, accounting_routes_malformed,
            accounting_routes_dependency_unavailable,
            accounting_routes_access_denied or accounting_routes_unreadable),
            tenant_policy_document_invalid (the stored document is refused by
            the parser: replace it first) or tenant_policy_document_full (the
            stored document already lists 100 organizations, none of them this
            one). Absent when exportable is true.
          type: string
      required:
        - organizationId
        - ledgerId
        - exportable
        - discovered
      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
    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.