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

# Create Transaction

> The Record Transaction API endpoint is the core method for creating and executing financial transactions in the Nxos system. It allows you to create complex, multi-asset transactions consisting of one or more asset moves, all processed atomically. 
This endpoint supports various transaction types, from simple transfers to intricate multi-hop exchanges, and includes features like idempotency through transaction references and metadata support for both transactions and individual asset moves. 
Importantly, the asset moves within a transaction are executed sequentially in the order they're included, allowing for self-funding chains where later moves can depend on the balance changes from earlier moves.



## OpenAPI

````yaml ledger-openapi POST /v1/ledger/{ledger_key}/transaction
openapi: 3.0.0
info:
  title: Ledger API
  version: 0.0.0
servers:
  - url: https://api.sandbox.nxos.io
    description: single server endpoint
    variables: {}
security: []
tags: []
paths:
  /v1/ledger/{ledger_key}/transaction:
    post:
      summary: Record Transaction
      description: >-
        The Record Transaction API endpoint is the core method for creating and
        executing financial transactions in the Nxos system. It allows you to
        create complex, multi-asset transactions consisting of one or more asset
        moves, all processed atomically. 

        This endpoint supports various transaction types, from simple transfers
        to intricate multi-hop exchanges, and includes features like idempotency
        through transaction references and metadata support for both
        transactions and individual asset moves. 

        Importantly, the asset moves within a transaction are executed
        sequentially in the order they're included, allowing for self-funding
        chains where later moves can depend on the balance changes from earlier
        moves.
      operationId: Transactions_recordTxn
      parameters:
        - $ref: '#/components/parameters/BasicAuthHeader'
        - $ref: '#/components/parameters/LedgerKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateTransactionRequest'
      responses:
        '200':
          description: The request has succeeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Transaction'
components:
  parameters:
    BasicAuthHeader:
      name: Authorization
      in: header
      required: true
      description: |-
        The Basic Authentication header.
        Format: "Basic {base64(orgID:apiKey)}"
      schema:
        type: string
    LedgerKey:
      name: ledger_key
      in: path
      required: true
      description: |-
        The key of the ledger. 
        Examples: 
        - "123e4567-e89b-12d3-a456-426614174000"
        - "id:123e4567-e89b-12d3-a456-426614174000"
        - "ref:ledger:customer_a"
      schema:
        type: string
  schemas:
    CreateTransactionRequest:
      type: object
      required:
        - asset_moves
      properties:
        transaction_ref:
          type: string
          minLength: 1
          description: >-
            The reference of the transaction - needs to be unique for the
            transaction, can be anything from a UUID to a reference of your
            choice. This is the reference you will use to interact with the
            transaction.

            This reference also guarantees idempotency, so if you send the same
            transaction reference twice, the second request will be ignored.
        asset_moves:
          type: array
          items:
            $ref: '#/components/schemas/AssetMoveRequest'
          description: The asset moves for the transaction
    Transaction:
      type: object
      required:
        - transaction_id
        - asset_moves
        - created_at
        - updated_at
      properties:
        transaction_id:
          type: string
          format: uuid
          description: The unique internally assigned identifier of the transaction
        transaction_ref:
          type: string
          description: The externally defined reference of the transaction
        asset_moves:
          type: array
          items:
            $ref: '#/components/schemas/AssetMove'
          description: The asset moves for the transaction
        created_at:
          type: string
          format: date-time
          description: The created at timestamp
        updated_at:
          type: string
          format: date-time
          description: The updated at timestamp
    AssetMoveRequest:
      type: object
      required:
        - source_account
        - destination_account
        - asset_code
        - amount
      properties:
        asset_move_ref:
          type: string
          minLength: 1
          description: >-
            The reference of the asset move - needs to be unique for the asset
            move, can be anything from a UUID to a reference of your choice.
            This is the reference you will use to interact with the asset move.
        source_account:
          allOf:
            - $ref: '#/components/schemas/AssetMoveAccount'
          description: The representation of the source account
        destination_account:
          allOf:
            - $ref: '#/components/schemas/AssetMoveAccount'
          description: The represantation of the destination account
        asset_code:
          type: string
          minLength: 1
          description: The reference of the asset
        amount:
          type: string
          description: The amount of the asset to move
        type:
          type: string
          minLength: 1
          description: >-
            The type of the asset move - as defined by the client, defaults to
            "TRANSFER"
        categories:
          type: array
          items:
            type: string
          description: >-
            Additional, optional, categories to classify the asset move, such as
            'CARD' or 'BANK'
        metadata:
          type: object
          additionalProperties: {}
          description: >-
            Additional, optional, metadata for the asset move, this can include
            things like external stripe-ids, or other data you would like to
            store with the asset-move
    AssetMove:
      type: object
      required:
        - asset_move_ref
        - source_account
        - destination_account
        - asset_code
        - amount
        - status
        - type
        - created_at
        - updated_at
      properties:
        asset_move_ref:
          type: string
          format: uuid
          description: >-
            The unique reference of the asset move, set by you when creating the
            asset move
        source_account:
          allOf:
            - $ref: '#/components/schemas/AssetMoveAccount'
          description: The representation of the source account
        destination_account:
          allOf:
            - $ref: '#/components/schemas/AssetMoveAccount'
          description: The represantation of the destination account
        asset_code:
          type: string
          minLength: 1
          description: The reference of the asset
        amount:
          type: string
          description: The amount of the asset to move
        status:
          allOf:
            - $ref: '#/components/schemas/AssetMoveStatus'
          description: The status of the asset move
        type:
          type: string
          minLength: 1
          description: The type of the asset move
        decline_type:
          type: string
          description: >-
            the specific decline reason for the asset move in case the
            asset-move has been declined. 

            This can be a system-defined reason such as INSUFFICIENT_FUNDS, or
            LIMIT_EXCEEDED, or it can be

            a custom defined type of so set during the transaction creation
        categories:
          type: array
          items:
            type: string
          description: The categories of the asset move
        metadata:
          type: object
          additionalProperties: {}
          description: Additional, optional, metadata for the asset move
        created_at:
          type: string
          format: date-time
          description: The created at timestamp
        updated_at:
          type: string
          format: date-time
          description: The updated at timestamp
    AssetMoveAccount:
      type: object
      properties:
        ref:
          type: string
          description: The user-defined reference of the account.
        id:
          type: string
          description: The system-generated ID of the account.
      description: >-
        Represents an account reference for asset moves.

        Used to specify source or destination accounts in asset movement
        operations.

        Exactly one of 'ref' or 'id' must be provided.
    AssetMoveStatus:
      type: string
      enum:
        - EXPECTED
        - LOCKED
        - COMPLETED
        - DECLINED
        - REFUNDED
      description: >-
        Represents the current status of an asset move.

        Asset moves are transfers of assets between accounts and form the basis
        of transactions.

        Note: LOCKED and COMPLETED statuses affect account balances, while

        EXPECTED, DECLINED, and REFUNDED do not impact or release cap

````