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

# Revert a completed operation (contraasiento)

> Creates dashboard contraasientos for every completed transaction in the operation. The original operation and transaction amounts, accounts, and legs stay in history; originals become adjusted and inverse transactions are inserted on the same operation (the same helper as dashboard Revertir operación). Completed operations are immutable: this is not an unapprove or completed→pending flip. Cheque-linked operations are rejected, matching the dashboard. Optional body: `{ "description": "reason" }`.



## OpenAPI

````yaml /docs/openapi.json post /api/operations/{id}/revert
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/operations/{id}/revert:
    post:
      tags:
        - Operations
      summary: Revert a completed operation (contraasiento)
      description: >-
        Creates dashboard contraasientos for every completed transaction in the
        operation. The original operation and transaction amounts, accounts, and
        legs stay in history; originals become adjusted and inverse transactions
        are inserted on the same operation (the same helper as dashboard
        Revertir operación). Completed operations are immutable: this is not an
        unapprove or completed→pending flip. Cheque-linked operations are
        rejected, matching the dashboard. Optional body: `{ "description":
        "reason" }`.
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: integer
          description: Completed operation ID to revert
      requestBody:
        required: false
        content:
          application/json:
            schema:
              type: object
              properties:
                description:
                  type: string
                  description: >-
                    Optional extra text appended to each contraasiento
                    description
            example:
              description: Reload as budget operation
      responses:
        '200':
          description: Operation reverted with counterpart transactions
          content:
            application/json:
              schema:
                type: object
                properties:
                  operation_id:
                    type: integer
                    description: Original operation ID (unchanged)
                  counterpart_operation_id:
                    type: integer
                    description: >-
                      Operation that holds the inverse legs. Dashboard
                      contraasiento posts those legs on the same operation, so
                      this equals operation_id.
                  counterpart_transaction_ids:
                    type: array
                    items:
                      type: integer
                    description: IDs of the newly inserted inverse transactions
                  adjusted_transaction_ids:
                    type: array
                    items:
                      type: integer
                    description: Original transaction IDs now marked adjusted
                  adjusted_transactions:
                    type: integer
                    description: Number of original transactions marked adjusted
                  message:
                    type: string
              example:
                operation_id: 123
                counterpart_operation_id: 123
                counterpart_transaction_ids:
                  - 456
                  - 457
                adjusted_transaction_ids:
                  - 10
                  - 11
                adjusted_transactions: 2
                message: Operation reverted successfully
        '400':
          description: Invalid operation ID or operation has no transactions
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
              example:
                error: Operation has no transactions to revert
        '401':
          description: Unauthorized - Missing or invalid API key
        '404':
          description: Operation not found or belongs to another company
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
              example:
                error: Operation not found
        '409':
          description: Operation is not fully completed, already reverted, or cheque-linked
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
              examples:
                notCompleted:
                  value:
                    error: Cannot revert operation with non-completed transactions
                alreadyReverted:
                  value:
                    error: Cannot revert an already-reverted operation
                cheque:
                  value:
                    error: Cannot revert a cheque operation
        '500':
          description: Server error
      security:
        - apiKey: []
components:
  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.