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

# Mesa report for the open period or a closed snapshot

> Same query as the dashboard (page, pageSize, search, side, status, inclusion, sortKey, sortDir), plus optional period_id. Omit period_id for the live open day (409 NO_OPEN_PERIOD when none is open). Pass a closed period_id to serve the frozen closing_report blotter (two columns, WAC, leftover, P&L, lines) with readOnly=true — not a live replay. Reopen that day (`POST .../periods/{periodId}/reopen`) to make it editable again. 409 SNAPSHOT_MISSING when that closed day has no usable snapshot. Aggregates and blotter are full-period; report.perTrade and trades are the current page.



## OpenAPI

````yaml /docs/openapi.json get /api/mesas/{id}/report
openapi: 3.0.0
info:
  title: FinSync API Documentation
  version: 1.0.0
  description: API documentation for FinSync application
  contact:
    name: FinSync Support
    email: support@finsync.com
servers:
  - url: https://api.finsync.ar
    description: Direct Fly API (preferred for API keys and webhooks)
  - url: https://finsync.ar
    description: Same-origin via finsync.ar (Vercel rewrite)
security:
  - apiKey: []
tags:
  - name: Clients
    description: Operations related to clients and their accounts
  - name: Tags
    description: >-
      Company-scoped client labels (Configuración > Etiquetas). Distinct from
      the special Centro de resultados / Centro de costos tag used for budget
      clients.
  - name: Accounts
    description: Operations related to account balances
  - name: Cost Centers
    description: Company centros de resultados (cost_center_id) and their budgets
  - name: Operations
    description: Operations for creating and managing financial operations
  - name: Operation Types
    description: Company operation types management
  - name: Transaction Types
    description: Company transaction types management
  - name: WhatsApp Tools
    description: >-
      Company-scoped WhatsApp bot operation tools (Configuración > WhatsApp >
      Tools). Same WhatsAppOperationTool rows as the dashboard. Authenticate
      with x-api-key.
  - name: External client
    description: >-
      Exports for external (portal-linked) clients. Authenticate with
      `x-api-key` (company-owned client ID) or `Authorization: Bearer` (Auth.js
      session for an ExternalAccessGrant).
  - name: Mesas
    description: >-
      Company FX trading desks (mesas). Same records and paths as the dashboard
      Mesas module. Integrators authenticate with x-api-key; the dashboard uses
      an employee session. Superadmin must set mesas_enabled first; there is no
      public PATCH for that flag. created_by / opened_by / closed_by are null
      for API-key callers.
  - name: Home metrics
    description: >-
      Named dashboard home metrics (list + values). API keys receive the
      Métricas-group cards (day P&L, commissions, cost centers) without the
      metrics-password cookie. Employee sessions need the matching view
      permission; they still skip the UI password gate on this surface.
paths:
  /api/mesas/{id}/report:
    get:
      tags:
        - Mesas
      summary: Mesa report for the open period or a closed snapshot
      description: >-
        Same query as the dashboard (page, pageSize, search, side, status,
        inclusion, sortKey, sortDir), plus optional period_id. Omit period_id
        for the live open day (409 NO_OPEN_PERIOD when none is open). Pass a
        closed period_id to serve the frozen closing_report blotter (two
        columns, WAC, leftover, P&L, lines) with readOnly=true — not a live
        replay. Reopen that day (`POST .../periods/{periodId}/reopen`) to make
        it editable again. 409 SNAPSHOT_MISSING when that closed day has no
        usable snapshot. Aggregates and blotter are full-period; report.perTrade
        and trades are the current page.
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: integer
          description: Mesa ID
        - in: query
          name: period_id
          schema:
            type: integer
          description: Closed (or open) period to load. Omit for the current open day.
        - in: query
          name: page
          schema:
            type: integer
            default: 1
        - in: query
          name: pageSize
          schema:
            type: integer
            default: 25
        - in: query
          name: search
          schema:
            type: string
          description: Filter trades by description / operation type text
        - in: query
          name: side
          schema:
            type: string
            enum:
              - all
              - buy
              - sell
            default: all
        - in: query
          name: status
          schema:
            type: string
            enum:
              - all
              - open
              - matched
            default: all
        - in: query
          name: inclusion
          schema:
            type: string
            enum:
              - all
              - auto
              - manual
            default: all
        - in: query
          name: sortKey
          schema:
            type: string
            enum:
              - date
              - localAmount
              - fx
              - pnlQuote
            default: date
        - in: query
          name: sortDir
          schema:
            type: string
            enum:
              - asc
              - desc
            default: desc
      responses:
        '200':
          description: Live open-period report or frozen closed-period snapshot
          content:
            application/json:
              schema:
                type: object
                properties:
                  mesa:
                    $ref: '#/components/schemas/Mesa'
                  period:
                    $ref: '#/components/schemas/MesaPeriod'
                  report:
                    type: object
                  blotter:
                    type: object
                  trades:
                    type: array
                    items:
                      type: object
                  pagination:
                    type: object
                  readOnly:
                    type: boolean
              example:
                mesa:
                  id: 1
                  company_id: 42
                  name: ARS/USD desk
                  local_currency: ARS
                  quote_currency: USD
                  costing_method: fifo
                  account_ids:
                    - 10
                    - 11
                  created_by: null
                  created_at: '2026-03-01T00:00:00.000Z'
                  updated_at: '2026-03-01T00:00:00.000Z'
                  deleted_at: null
                period:
                  id: 5
                  mesa_id: 1
                  status: open
                  opened_at: '2026-03-01T00:00:00.000Z'
                  closed_at: null
                  opening_local: 1000000
                  opening_fx: 1200
                  closing_local: null
                  closing_avg_fx: null
                  pnl_local: null
                  pnl_quote: null
                  closing_report: null
                  opened_by: null
                  closed_by: null
                  created_at: '2026-03-01T00:00:00.000Z'
                  updated_at: '2026-03-01T00:00:00.000Z'
                report:
                  method: fifo
                  totals:
                    pnlLocal: 15000
                    pnlQuote: 12.4
                    tradeCount: 3
                  position:
                    openLongLocal: 250000
                    averageCostFx: 1210
                  perTrade: []
                trades: []
                pagination:
                  page: 1
                  pageSize: 25
                  total: 0
                  totalPages: 0
                readOnly: false
        '400':
          description: Invalid mesa ID
        '401':
          description: Unauthorized - Missing or invalid API key
        '403':
          description: >-
            Mesas module not enabled for this company (superadmin must set
            mesas_enabled). No public PATCH for that flag.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MesasDisabledError'
              example:
                error: Mesas module not enabled for this company
                code: MESAS_DISABLED
        '404':
          description: Mesa not found, or period_id does not belong to this mesa
        '409':
          description: >-
            No open period (omit period_id), or closed period snapshot is
            missing
          content:
            application/json:
              examples:
                noOpenPeriod:
                  value:
                    error: No open period
                    code: NO_OPEN_PERIOD
                snapshotMissing:
                  value:
                    error: Closed period snapshot is missing
                    code: SNAPSHOT_MISSING
        '500':
          description: Server error
      security:
        - apiKey: []
components:
  schemas:
    Mesa:
      type: object
      description: >-
        FX trading desk. created_by is null for x-api-key creates. account_ids
        are internal (Client.type=0) accounts unique to one mesa.
      properties:
        id:
          type: integer
          example: 1
        company_id:
          type: integer
          example: 42
        name:
          type: string
          example: ARS/USD desk
        local_currency:
          type: string
          example: ARS
        quote_currency:
          type: string
          example: USD
        costing_method:
          type: string
          enum:
            - fifo
            - wac
          example: wac
        perspective:
          type: string
          enum:
            - local
            - quote
          description: 'quote: Compra = quote in = engine sell. New desks default to quote.'
          example: quote
        feed_mode:
          type: string
          enum:
            - auto
            - manual
          description: >-
            manual: blotter starts empty (user confirms lines). auto: apply
            high-confidence Sugerir matches (exact / fx_close) as blotter lines;
            links never write operations. New desks default to manual.
          example: manual
        include_pending:
          type: boolean
          description: >-
            Off (default): Sugerir / auto-feed / infer only count completed
            legs. On: pending legs count too. Cancel drops the blotter line;
            approve keeps the same link.
          example: false
        account_ids:
          type: array
          items:
            type: integer
          example:
            - 10
            - 11
        created_by:
          type: integer
          nullable: true
          example: null
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
        deleted_at:
          type: string
          format: date-time
          nullable: true
      example:
        id: 1
        company_id: 42
        name: ARS/USD desk
        local_currency: ARS
        quote_currency: USD
        costing_method: fifo
        account_ids:
          - 10
          - 11
        created_by: null
        created_at: '2026-03-01T00:00:00.000Z'
        updated_at: '2026-03-01T00:00:00.000Z'
        deleted_at: null
    MesaPeriod:
      type: object
      description: Trading session. opened_by / closed_by are null for x-api-key callers.
      properties:
        id:
          type: integer
          example: 5
        mesa_id:
          type: integer
          example: 1
        status:
          type: string
          enum:
            - open
            - closed
        opened_at:
          type: string
          format: date-time
        closed_at:
          type: string
          format: date-time
          nullable: true
        opening_local:
          type: number
          example: 1000000
        opening_fx:
          type: number
          nullable: true
          example: 1200
        closing_local:
          type: number
          nullable: true
        closing_avg_fx:
          type: number
          nullable: true
        pnl_local:
          type: number
          nullable: true
        pnl_quote:
          type: number
          nullable: true
        closing_report:
          type: object
          nullable: true
        opened_by:
          type: integer
          nullable: true
          example: null
        closed_by:
          type: integer
          nullable: true
          example: null
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
      example:
        id: 5
        mesa_id: 1
        status: open
        opened_at: '2026-03-01T00:00:00.000Z'
        closed_at: null
        opening_local: 1000000
        opening_fx: 1200
        closing_local: null
        closing_avg_fx: null
        pnl_local: null
        pnl_quote: null
        closing_report: null
        opened_by: null
        closed_by: null
        created_at: '2026-03-01T00:00:00.000Z'
        updated_at: '2026-03-01T00:00:00.000Z'
    MesasDisabledError:
      type: object
      properties:
        error:
          type: string
          example: Mesas module not enabled for this company
        code:
          type: string
          example: MESAS_DISABLED
  securitySchemes:
    apiKey:
      type: apiKey
      in: header
      name: x-api-key
      description: API Key for authentication

````

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