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

# Record a return

> Records a return (for example an ACH return or a reversed card payment) of a payment and reconciles it to the bank transaction that moved the money back. End Close creates a new record with `record_type` `return` on the payment's data stream. Its amount is the bank transaction's amount, its direction is opposite to the payment, and its `return_of` is the payment. The return is matched to the bank transaction. The payment keeps its own match, if it has one, and lists the return under `returns`, so this works for a return that arrives before or after the payment is matched.

The payment and the bank transaction must be on opposite sides of the reconciliation, move money in opposite directions, and use the same currency. The bank transaction must be unreconciled in this reconciliation. A partial return (a bank amount below the payment amount) is allowed. A payment can have several returns, but together they cannot exceed the payment amount. When the returns add up to less than the payment amount, End Close also keeps a `residual` record open for the rest, on the reconciliation's adjustments data stream. It has the payment's direction and currency, and its `residual_of` is the payment. Each later return replaces it, and a full return deletes it. A return is refused while the residual is matched or written off.



## OpenAPI

````yaml /openapi.json post /reconciliations/{reconciliation_id}/returns
openapi: 3.1.0
info:
  title: End Close API
  description: REST API is used to interact with the End Close platform.
  license:
    name: MIT
  version: 1.0.0
servers:
  - url: https://api.endclose.com/v1
security:
  - ApiKeyAuth: []
paths:
  /reconciliations/{reconciliation_id}/returns:
    post:
      summary: Record a return
      description: >-
        Records a return (for example an ACH return or a reversed card payment)
        of a payment and reconciles it to the bank transaction that moved the
        money back. End Close creates a new record with `record_type` `return`
        on the payment's data stream. Its amount is the bank transaction's
        amount, its direction is opposite to the payment, and its `return_of` is
        the payment. The return is matched to the bank transaction. The payment
        keeps its own match, if it has one, and lists the return under
        `returns`, so this works for a return that arrives before or after the
        payment is matched.


        The payment and the bank transaction must be on opposite sides of the
        reconciliation, move money in opposite directions, and use the same
        currency. The bank transaction must be unreconciled in this
        reconciliation. A partial return (a bank amount below the payment
        amount) is allowed. A payment can have several returns, but together
        they cannot exceed the payment amount. When the returns add up to less
        than the payment amount, End Close also keeps a `residual` record open
        for the rest, on the reconciliation's adjustments data stream. It has
        the payment's direction and currency, and its `residual_of` is the
        payment. Each later return replaces it, and a full return deletes it. A
        return is refused while the residual is matched or written off.
      parameters:
        - in: path
          name: reconciliation_id
          required: true
          schema:
            type: string
          description: The reconciliation to reconcile the return in
        - in: header
          name: Idempotency-Key
          schema:
            type: string
            maxLength: 255
          description: >-
            Optional. Send the same key when retrying a write you are not sure
            landed: the first response is returned again (with
            Idempotent-Replayed: true) instead of writing twice. A key used for
            a different request is refused with 422; one whose first request is
            still running gets 409. A refused or failed request does not use up
            its key. Keys are per environment and kept for 7 days.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - payment_record_id
                - bank_record_id
              properties:
                payment_record_id:
                  type: string
                  description: >-
                    The payment that was returned (for example the system
                    transaction).
                bank_record_id:
                  type: string
                  description: >-
                    The bank transaction that moved the money back. Its amount
                    is the amount returned.
                reason:
                  type: string
                  description: >-
                    Optional. The return reason, for example an ACH return code
                    such as `R01`. Stored in the return record's
                    `metadata.return_reason` and its description.
      responses:
        '201':
          description: Return recorded and reconciled
          content:
            application/json:
              schema:
                type: object
                properties:
                  return_record:
                    $ref: '#/components/schemas/Record'
                  reconciliation_match:
                    $ref: '#/components/schemas/ReconciliationMatch'
                  residual_record:
                    nullable: true
                    description: >-
                      The open residual for the part of the payment that is not
                      returned yet. `null` when the payment is now fully
                      returned.
                    allOf:
                      - $ref: '#/components/schemas/Record'
        '401':
          description: Unauthorized
        '404':
          description: Reconciliation or record not found
        '409':
          description: The bank transaction is already reconciled in this reconciliation
        '422':
          description: >-
            Validation error (missing fields, records on the same side, same
            direction, different currency, or a return larger than what is left
            of the payment)
components:
  schemas:
    Record:
      type: object
      required:
        - date
        - data_stream_key
        - amount
        - direction
      properties:
        id:
          type: string
          format: uuid
        amount:
          type: integer
          description: The monetary amount in cents (e.g., 1234 = $12.34)
        currency:
          type: string
          description: >-
            Three-letter ISO 4217 currency code (e.g. USD, EUR). **Optional on
            create — defaults to `USD` when omitted.** Case-insensitive on
            input; always returned uppercase.
          pattern: ^[A-Za-z]{3}$
          default: USD
        decimal_places:
          type: integer
          description: Number of decimal places for this currency (2 for USD)
          default: 2
        direction:
          type: string
          enum:
            - credit
            - debit
        description:
          type: string
        date:
          type: string
          format: date
        metadata:
          type: object
          additionalProperties: true
          default: {}
        external_id:
          type: string
        data_stream_key:
          type: string
        bank_account:
          readOnly: true
          nullable: true
          description: >-
            The bank account the record sits in: the account of its `bank_feed`
            data stream. `null` for a record on any other kind of stream.
          allOf:
            - $ref: '#/components/schemas/RecordBankAccount'
        record_type:
          type: string
          enum:
            - payment
            - return
            - residual
          readOnly: true
          description: >-
            `return` for a record that reverses an earlier payment (for example
            an ACH return). `residual` for the part of a partly returned payment
            that did not come back. Every other record is a `payment`.
        return_of:
          readOnly: true
          nullable: true
          description: On a return, the payment it reverses. `null` on a payment.
          allOf:
            - $ref: '#/components/schemas/RecordReference'
        returns:
          type: array
          readOnly: true
          description: >-
            On a payment, the returns that reverse it. A payment with a return
            is returned.
          items:
            $ref: '#/components/schemas/RecordReference'
        residual_of:
          readOnly: true
          nullable: true
          description: >-
            On a residual, the partly returned payment. `null` on every other
            record.
          allOf:
            - $ref: '#/components/schemas/RecordReference'
        residual:
          readOnly: true
          nullable: true
          description: >-
            On a partly returned payment, the residual: an open record for the
            payment amount minus its returns. End Close creates it when a
            partial return is recorded, replaces it when another return changes
            the amount, and deletes it when the payment is fully returned.
            `matched` is `true` once someone matched or wrote off the residual.
            `null` when the payment has no residual.
          allOf:
            - $ref: '#/components/schemas/RecordReference'
            - type: object
              properties:
                matched:
                  type: boolean
        split_from_record_id:
          type: string
          format: uuid
          readOnly: true
          nullable: true
          description: >-
            On a record End Close wrote for a partial match, the record it was
            split from. `null` on every other record.
        split_role:
          type: string
          enum:
            - carve_out
            - remainder
          readOnly: true
          nullable: true
          description: >-
            `remainder` for the open part of a partially matched record, carried
            forward to be matched later. `carve_out` for the record that takes
            that open part out of the partial match. `null` on every other
            record.
        split_from:
          readOnly: true
          nullable: true
          description: On a carve-out or remainder, the record it was split from.
          allOf:
            - $ref: '#/components/schemas/RecordReference'
        partially_matched:
          type: boolean
          readOnly: true
          description: >-
            Whether the record's match covers only part of it, with the rest
            left open as a remainder.
        partially_matched_reconciliation_ids:
          type: array
          readOnly: true
          description: The reconciliations the record is partially matched in.
          items:
            type: string
            format: uuid
        split:
          type: object
          readOnly: true
          nullable: true
          description: >-
            On a partially matched record, how much of it is matched and how
            much is still open, within the reconciliation it was partially
            matched in. `null` when the record was never partially matched, or
            when it was partially matched in more than one reconciliation (a
            record on a shared feed); each reconciliation's split is then on the
            record's entry in that reconciliation.
          properties:
            matched_amount:
              type: integer
              description: The amount matched so far, in cents.
            open_amount:
              type: integer
              description: The amount still open, in cents.
            fully_matched:
              type: boolean
              description: Whether every remainder is matched.
            parts:
              type: integer
              description: >-
                How many matches the record is split across once every remainder
                is matched.
            remainders:
              type: array
              items:
                allOf:
                  - $ref: '#/components/schemas/RecordReference'
                  - type: object
                    properties:
                      matched:
                        type: boolean
    ReconciliationMatch:
      type: object
      description: >-
        A reconciliation match represents a group of records that have been
        matched together. Endclose supports many-to-one matching, so a single
        match can contain a large number of records — to retrieve them, use `GET
        /v1/records?reconciliation_match_id={id}`.
      properties:
        id:
          type: string
          format: uuid
        status:
          type: string
          description: >-
            `pending_review` while the match waits for someone to approve it: a
            rule with `requires_approval` found it, or the reconciliation's
            approval settings held a manual match. Its records stay unmatched
            until then. `rejected` once a reviewer rejects it. `matched` once a
            held match is approved. Other matches carry `partial`.
        group_key:
          type: string
        reconciliation_id:
          type: string
          format: uuid
        reconciliation_rule_id:
          type: string
          format: uuid
        created_at:
          type: string
          format: date-time
        record_count:
          type: integer
          description: Total number of records in this match
    RecordBankAccount:
      type: object
      description: The bank account a record sits in, in short.
      properties:
        id:
          type: string
          format: uuid
        name:
          type: string
        mask:
          type: string
          nullable: true
          description: The last digits of the account number, as the bank shows them.
        display_name:
          type: string
          description: >-
            The name with the mask, for example `Partner Bank Incoming (7710)`.
            The name alone when no mask is known.
    RecordReference:
      type: object
      description: A short reference to another record.
      properties:
        id:
          type: string
          format: uuid
        amount:
          type: integer
          description: The monetary amount in cents
        currency:
          type: string
        decimal_places:
          type: integer
        direction:
          type: string
          enum:
            - credit
            - debit
        description:
          type: string
        date:
          type: string
          format: date
        external_id:
          type: string
          nullable: true
        data_stream_key:
          type: string
        bank_account:
          nullable: true
          description: >-
            The account of the record's `bank_feed` data stream. `null` on any
            other kind of stream.
          allOf:
            - $ref: '#/components/schemas/RecordBankAccount'
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-KEY

````

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