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

# Create swap

> Swaps between supported API swap currencies.



## OpenAPI

````yaml /openapi.json post /v3/swap
openapi: 3.1.0
info:
  title: Sarafa Merchant API
  summary: Enterprise API for Sarafa merchants.
  description: >-
    The Sarafa Merchant API is mounted under `/v3` and authenticated with a
    merchant API secret.
  version: 0.1.0
servers:
  - url: https://serviceapi.sarafa.ss
    description: Production
security:
  - ApiKeyAuth: []
tags:
  - name: Profile
  - name: Wallets
  - name: Money movement
  - name: Transactions
  - name: Rates
paths:
  /v3/swap:
    post:
      tags:
        - Money movement
      summary: Create swap
      description: Swaps between supported API swap currencies.
      operationId: createSwap
      parameters:
        - $ref: '#/components/parameters/EnvironmentHeader'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SwapRequest'
            example:
              _from: USD
              _to: SSP
              amount: 10
              external_id: swap-001
              quote: false
      responses:
        '200':
          description: Swap quote or executed swap legs.
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/QuoteResponse'
                  - $ref: '#/components/schemas/SwapResponse'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/ServerError'
components:
  parameters:
    EnvironmentHeader:
      name: environment
      in: header
      required: false
      description: Target environment. Defaults to `production` when omitted.
      schema:
        type: string
        enum:
          - production
          - sandbox
        default: production
  schemas:
    SwapRequest:
      type: object
      additionalProperties: false
      required:
        - _from
        - _to
        - amount
      properties:
        _from:
          $ref: '#/components/schemas/ApiSwapCurrency'
        _to:
          $ref: '#/components/schemas/ApiSwapCurrency'
        amount:
          $ref: '#/components/schemas/Amount'
        fee_percent:
          type: number
          minimum: 0
          maximum: 10
        external_id:
          $ref: '#/components/schemas/ExternalReference'
        quote:
          type: boolean
          default: true
    QuoteResponse:
      type: object
      required:
        - status
        - data
      properties:
        status:
          type: string
          enum:
            - success
        data:
          type: object
          required:
            - quote
          properties:
            quote:
              $ref: '#/components/schemas/Quote'
    SwapResponse:
      type: object
      required:
        - status
        - data
      properties:
        status:
          type: string
          enum:
            - success
        data:
          type: object
          required:
            - quote
            - debit
            - credit
          properties:
            quote:
              $ref: '#/components/schemas/Quote'
            debit:
              $ref: '#/components/schemas/Transaction'
            credit:
              $ref: '#/components/schemas/Transaction'
    ApiSwapCurrency:
      type: string
      enum:
        - USD
        - SSP
    Amount:
      type: number
      exclusiveMinimum: 0
      maximum: 1000000000
    ExternalReference:
      type: string
      minLength: 3
      maxLength: 120
      pattern: ^[A-Za-z0-9._:-]+$
    Quote:
      type: object
      required:
        - from_currency
        - to_currency
        - amount
        - rate
        - fee
        - platform_fee
        - receive_amount
        - quoted_at
      properties:
        from_currency:
          $ref: '#/components/schemas/Currency'
        to_currency:
          $ref: '#/components/schemas/Currency'
        amount:
          type: number
        rate:
          type: number
        fee:
          type: number
        platform_fee:
          type: number
        receive_amount:
          type: number
        deposit_currency:
          $ref: '#/components/schemas/Currency'
        deposit_amount:
          type: number
        quoted_at:
          type: string
          format: date-time
    Transaction:
      type: object
      required:
        - total_amount
        - total_fee
        - product
        - description
        - status
        - created_at
        - updated_at
        - completed_at
        - external_reference
        - customer_meta
      properties:
        total_amount:
          type: number
        total_fee:
          type: number
        product:
          type: string
          examples:
            - collect_mobile
            - disburse_mobile
        description:
          type:
            - string
            - 'null'
        status:
          $ref: '#/components/schemas/Status'
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
        completed_at:
          type:
            - string
            - 'null'
          format: date-time
        external_reference:
          type:
            - string
            - 'null'
        customer_meta:
          type:
            - object
            - 'null'
          additionalProperties: true
    ErrorResponse:
      type: object
      required:
        - status
        - message
      properties:
        status:
          type: string
          enum:
            - error
        message:
          type: string
    Currency:
      type: string
      enum:
        - USD
        - SSP
        - UGX
        - KES
        - NGN
        - USDT
        - USDC
    Status:
      type: string
      examples:
        - pending
        - processing
        - completed
        - failed
  responses:
    BadRequest:
      description: >-
        Invalid request data, unsupported currency, unsupported pair, or invalid
        phone number.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            status: error
            message: Invalid request data
    Unauthorized:
      description: Missing or invalid API key.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            missingApiKey:
              value:
                status: error
                message: API key is required
            invalidApiKey:
              value:
                status: error
                message: Invalid API key
    Forbidden:
      description: Organization or account context could not be resolved.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            status: error
            message: Organization account not found
    NotFound:
      description: Requested wallet or resource was not found.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            status: error
            message: Wallet not found
    ServerError:
      description: Unexpected server error.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            status: error
            message: Something went wrong. Request could not be processed
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key
      description: Merchant API secret.

````