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

# Legacy API (migrated merchants)

This page is for merchants who moved from the old Pesaswap platform and still call its endpoints. Those endpoints keep working on the current platform, under the `/api` path, with the same request and response shapes as before.

If you are building a new integration, do not use these endpoints. Use the main API instead, starting with the [Payouts guide](https://docs.pesaswap.io/essentials/payments-guide/payouts.md).

| Environment | Base URL |
| - | - |
| Sandbox | `https://api.sandbox.pesaswap.io` |
| Production | `https://api.pesaswap.io` |

All examples below use the sandbox URL.

| Endpoint | What it does |
| - | - |
| `POST /api/tokenization` | Get an access token |
| `POST /api/collection-payment` | Collect money from a customer's mobile wallet |
| `POST /api/refund` | Refund a collection |
| `GET /api/balance` | Connector account balances (original format) |
| `GET /api/balance/v2` | Connector account balances (v2 format) |
| `GET /api/balance/v3` | Your Pesaswap wallet balance (original platform format) |
| `POST /api/disbursement-payment` | Send a payout to a mobile wallet, a bank account, a paybill or a till |
| `POST /api/choice-bank/imt-rails-transfer` | Send an IMT (international money transfer) payout |
| `GET /api/transactions/detail` | Status of one transaction |
| `GET /api/transactions/list` | List transactions for a date range |

> [!NOTE]
>
> Request field names are PascalCase (`TransactionExternalId`, `PhoneNumber`). `MerchantIdentifier` is accepted on every endpoint so existing integrations keep working, but it is not used. Your merchant account always comes from your access token.

## Authentication

### Get a token

`POST /api/tokenization` exchanges your consumer key and API key for an access token.

```bash curl theme={"system"}
curl --request POST \
  --url https://api.sandbox.pesaswap.io/api/tokenization \
  --header "Content-Type: application/json" \
  --data '{
    "ConsumerKey": "<your merchant identifier>",
    "ApiKey": "{{api_key}}"
  }'
```

| Field | Type | Required | Description |
| - | - | - | - |
| `ConsumerKey` | string | Yes | Your merchant identifier. It must belong to the same merchant as `ApiKey`. |
| `ApiKey` | string | Yes | Your Pesaswap API key. |

**Response `200`**

```json theme={"system"}
{
  "accessToken": "{{token}}",
  "expiry": "Thu, 26 Nov 2026 09:30:00 +0000"
}
```

The token is valid for 24 hours. `expiry` is the time it stops working, in RFC 2822 format. Request a new token before then.

**Errors**

| Status | Body | Cause |
| - | - | - |
| `401` | `{"error":"Invalid Credentials. Please Check your consumer_key and api_key."}` | The API key does not exist or has expired, or `ConsumerKey` does not match the merchant that owns the API key. |

### Send the token

Send the token in the `Authorization` header on every other call. Send it as is, with no prefix. A `Bearer ` prefix is also accepted.

```bash theme={"system"}
--header "Authorization: {{token}}"
```

A missing, invalid or expired token returns:

```json theme={"system"}
{ "error": "Invalid Credentials. Please Check your consumer_key and api_key." }
```

with status `401`. An API key that is revoked or expires after you got the token also makes the token stop working.

> [!WARNING]
>
> Always send `Content-Type: application/json` on calls that have a JSON body. Without it, most endpoints reject the request with a `400` before reading it.

## Collections

`POST /api/collection-payment` asks a customer to pay from their mobile wallet. For M-Pesa, the customer gets an STK push prompt on their phone.

```bash curl theme={"system"}
curl --request POST \
  --url https://api.sandbox.pesaswap.io/api/collection-payment \
  --header "Authorization: {{token}}" \
  --header "Content-Type: application/json" \
  --data '{
    "MerchantIdentifier": "<your merchant identifier>",
    "Country": "KE",
    "Currency": "KES",
    "Amount": "100.00",
    "PhoneNumber": "254700000000",
    "TransactionExternalId": "order-10001",
    "Comment": "Order 10001",
    "Processor": "mpesa"
  }'
```

| Field | Type | Required | Description |
| - | - | - | - |
| `Country` | string | Yes | ISO 3166-1 alpha-2 country code, such as `KE`. Case does not matter. |
| `Currency` | string | Yes | ISO 4217 currency code, such as `KES`. Case does not matter. |
| `Amount` | string or number | Yes | Amount in major units. `"100.00"` and `100` both mean 100 shillings. |
| `PhoneNumber` | string | Yes | The customer's phone number. `254700000000`, `+254700000000` and `0700000000` are all accepted. |
| `Processor` | string | Yes | `mpesa` or `coop` (both mean M-Pesa), `airtel`, or `mtn` / `momo`. Case does not matter. |
| `TransactionExternalId` | string | No | Your id for this collection. It becomes the transaction id. Use 1 to 64 characters: letters, digits, `_` and `-`. It must be unique. |
| `PaybillDescription` | string | No | Description of the payment. Used ahead of `Comment` if both are sent. |
| `Comment` | string | No | Description of the payment. |
| `MerchantIdentifier` | string | No | Accepted, not used. |

> [!WARNING]
>
> Always send `TransactionExternalId`. If you leave it out, Pesaswap generates an id but does not return it, so you have no way to look the transaction up later.

**Response `200`**

```json theme={"system"}
{ "Response": "Success. Request accepted for processing" }
```

This means the request was accepted. It does not mean the customer has paid. Wait for the [callback](#callbacks), or check the status with [`GET /api/transactions/detail`](#transaction-status).

**Errors**

| Status | Body | Cause |
| - | - | - |
| `400` | `{"error":"Missing required field: Processor."}` | `Processor` is not one of the accepted values. |
| `400` | `{"error":"Duplicate ExternalId."}` | A collection with this `TransactionExternalId` already exists. |
| `400` | `{"error":{"error_type":"invalid_request","message":"...","code":"IR_06"}}` | The body is not valid JSON, a required field is missing, or a value such as `Country` or `Currency` is not recognised. |
| `401` | `{"error":"Invalid Credentials. Please Check your consumer_key and api_key."}` | See [Authentication](#authentication). |
| `500` | `{"error":"Internal server error."}` | Any other failure, including a `TransactionExternalId` with characters outside letters, digits, `_` and `-`. |

## Refunds

`POST /api/refund` refunds a collection in full.

```bash curl theme={"system"}
curl --request POST \
  --url https://api.sandbox.pesaswap.io/api/refund \
  --header "Authorization: {{token}}" \
  --header "Content-Type: application/json" \
  --data '{
    "MerchantIdentifier": "<your merchant identifier>",
    "SourceTransactionExternalId": "order-10001",
    "RefundTransactionExternalId": "refund-10001"
  }'
```

| Field | Type | Required | Description |
| - | - | - | - |
| `SourceTransactionExternalId` | string | Yes | The `TransactionExternalId` of the collection to refund. |
| `RefundTransactionExternalId` | string | Yes | Your id for this refund. It must be unique. |
| `MerchantIdentifier` | string | No | Accepted, not used. |

There is no amount field. The full amount of the collection is refunded.

**Response `200`**

```json theme={"system"}
{ "Response": "Success. Request accepted for processing" }
```

**Errors**

| Status | Body | Cause |
| - | - | - |
| `400` | `{"error":"Missing required field: SourceTransactionExternalId."}` | `SourceTransactionExternalId` is missing. |
| `400` | `{"error":"Missing required field: RefundTransactionExternalId."}` | `RefundTransactionExternalId` is missing. |
| `400` | `{"error":"Transaction not found."}` | No collection has that `SourceTransactionExternalId`. |
| `400` | `{"error":"Duplicate ExternalId."}` | A refund with this `RefundTransactionExternalId` already exists. |
| `401` | `{"error":"Invalid Credentials. Please Check your consumer_key and api_key."}` | See [Authentication](#authentication). |
| `500` | `{"error":"Internal server error."}` | Any other failure. |

> [!NOTE]
>
> Refunds do not show up in `GET /api/transactions/detail`. To see a refund's status, use [`GET /api/transactions/list`](#list-transactions) with a date range.

## Balance

There are three balance endpoints:

* `/api/balance` and `/api/balance/v2` return the live balances of your connector accounts, such as your M-Pesa paybill or your Airtel account. Balances are fetched from each provider on every call, so a call can take a few seconds.
* `/api/balance/v3` returns your **Pesaswap wallet balance**: the balance your payouts are checked against. No provider is called. Use v3 if you need to know whether you can send a payout.

### Query parameters

| Parameter | Type | Required | Description |
| - | - | - | - |
| `Currency` | string | No | v1 and v2: only return accounts in this currency, such as `KES`. v3: the wallet currency to return. Defaults to `KES`. Case does not matter. |
| `Processor` | string | No | v1 ignores it. v3 echoes it back in `processor` and never rejects it. v2: only return accounts for this processor: `mpesa` or `coop` (both mean M-Pesa), `airtel`, `mtn` / `momo`, or `choice-bank` / `choicebank`. Case does not matter. |
| `MerchantIdentifier` | string | No | Accepted, not used. |
| `Country` | string | No | Accepted, not used. |

### GET /api/balance

```bash curl theme={"system"}
curl --request GET \
  --url "https://api.sandbox.pesaswap.io/api/balance?Currency=KES" \
  --header "Authorization: {{token}}"
```

**Response `200`**

```json theme={"system"}
{
  "response": [
    {
      "mpesaBalance": [
        {
          "account_id": "123456",
          "account_name": "Utility Account",
          "currency": "KES",
          "balance": "28400.00"
        }
      ],
      "airtelBalance": [],
      "mtnBalance": [],
      "choicebankBalance": []
    }
  ]
}
```

| Field | Description |
| - | - |
| `mpesaBalance`, `airtelBalance`, `mtnBalance`, `choicebankBalance` | One list per processor. Each item is one account. |
| `account_id` | The account number or shortcode. |
| `account_name` | The account name, as the provider reports it. |
| `currency` | The account currency. |
| `balance` | The balance, as a string in major units (`"28400.00"` is KES 28,400.00). |

Fields with no value are left out of the item. `/api/balance` ignores `Processor`, and its `mtnBalance` and `choicebankBalance` lists are always empty. Use v2 for MTN and Choice Bank.

### GET /api/balance/v2

```bash curl theme={"system"}
curl --request GET \
  --url "https://api.sandbox.pesaswap.io/api/balance/v2?Currency=KES&Processor=choice-bank" \
  --header "Authorization: {{token}}"
```

**Response `200`**

```json theme={"system"}
{
  "message": "",
  "response": [
    {
      "response": [
        {
          "processor": "ChoiceBank",
          "totalAmount": null,
          "payinFee": null,
          "payoutFee": null,
          "processorFee": null,
          "type": "B001",
          "currency": "KES"
        }
      ],
      "remainingCollectionBalance": 476055.0
    }
  ]
}
```

| Field | Description |
| - | - |
| `response` | One block per account. |
| `response[].remainingCollectionBalance` | The account balance, as a number in major units. `null` if the provider returned no balance. |
| `response[].response[].processor` | `Mpesa`, `Airtel`, `MTN` or `ChoiceBank`. |
| `response[].response[].type` | The account type, as the provider reports it. Can be `null`. |
| `response[].response[].currency` | The account currency. |
| `totalAmount`, `payinFee`, `payoutFee`, `processorFee` | Always `null`. Kept for compatibility. |
| `message` | Always an empty string. |

How v2 differs from `/api/balance`:

* v2 includes Choice Bank and MTN accounts. `/api/balance` does not.
* v2 honours `Processor`. `/api/balance` ignores it.
* v2 returns one block per account with the balance as a number. `/api/balance` groups accounts by processor with the balance as a string.

**Errors**

| Status | Body | Cause |
| - | - | - |
| `400` | `{"error":"Invalid Processor: <value>."}` | v2 only. `Processor` is not one of the accepted values. |
| `401` | `{"error":"Invalid Credentials. Please Check your consumer_key and api_key."}` | See [Authentication](#authentication). |
| `500` | `{"error":"Internal server error."}` | Any other failure. |

> [!NOTE]
>
> v1 and v2: if a provider cannot be reached, that account is left out and the rest of the response still returns. A missing account does not mean a zero balance.

### GET /api/balance/v3

Returns your Pesaswap wallet balance in the format of the original Pesaswap platform.

```bash curl theme={"system"}
curl --request GET \
  --url "https://api.sandbox.pesaswap.io/api/balance/v3?Country=KE&Currency=KES&MerchantIdentifier=<your merchant identifier>&Processor=choice-bank" \
  --header "Authorization: {{token}}"
```

**Response `200`**

```json theme={"system"}
{
  "remainingCollectionBalance": 4087.08,
  "response": [
    {
      "processor": "choice-bank",
      "type": "Disbursement",
      "accumulatedBalance": 4087.08,
      "currency": "KES",
      "totalGatewayFee": 5.3,
      "totalProcessorFee": 17.0
    }
  ]
}
```

| Field | Description |
| - | - |
| `remainingCollectionBalance` | Your wallet balance in `Currency`, as a number in major units (`4087.08` is KES 4,087.08). |
| `response` | Always exactly one entry. |
| `response[].processor` | The `Processor` you sent, exactly as sent. `pesaswap` if you did not send one. |
| `response[].type` | Always `Disbursement`. |
| `response[].accumulatedBalance` | The same wallet balance as `remainingCollectionBalance`. Do not add the two together. |
| `response[].currency` | The wallet currency. |
| `response[].totalGatewayFee` | Total Pesaswap gateway fees charged to your wallet in this currency, all time, in major units. |
| `response[].totalProcessorFee` | Total processor fees charged to your wallet in this currency, all time, in major units. |

* The balance can be negative.
* A currency you have never transacted in returns `0` for every amount, not an error.
* The fee totals are gross: fees on a payout that was later reversed are still counted, and the refunded fee shows up in your balance instead.

How v3 differs from `/api/balance` and v2:

* v3 returns your Pesaswap wallet balance. v1 and v2 return your connector account balances at each provider.
* v3 does not call any provider, so it is fast and always returns a value.
* `/api/balance` and `/api/balance/v2` are unchanged.

**Errors**

| Status | Body | Cause |
| - | - | - |
| `400` | Plain text starting `Query deserialize error` | `Currency` is not a recognised ISO 4217 code. |
| `401` | `{"error":"Invalid Credentials. Please Check your consumer_key and api_key."}` | See [Authentication](#authentication). |
| `500` | `{"error":"Internal server error."}` | Any other failure. |

## Payouts

`POST /api/disbursement-payment` sends money from your Pesaswap wallet. The `Processor` field decides where it goes:

| `Processor` | Sends to | Section |
| - | - | - |
| `mpesa`, `coop` | M-Pesa | [Mobile money](#mobile-money) |
| `airtel` | Airtel Money | [Mobile money](#mobile-money) |
| `mtn`, `momo` | MTN MoMo | [Mobile money](#mobile-money) |
| `pesalink` | A bank account, through PesaLink | [Bank](#bank) |
| `paybill` | An account at an M-Pesa paybill | [Bank](#bank) |
| `paytill` | An M-Pesa till number (Buy Goods) | [Bank](#bank) |
| `choice-bank-imt-rails` | An IMT transfer to M-Pesa | [IMT](#imt-through-disbursement-payment) |

> [!WARNING]
>
> `coop` always means M-Pesa (mobile money). To send a bank payout, set `Processor` to `pesalink`, `paybill` or `paytill`. Sending bank fields with `coop` sends an M-Pesa payout, not a bank one.

Every successful payout request returns the same response:

**Response `200`**

```json theme={"system"}
{ "Response": "Success. Request accepted for processing" }
```

This means the payout was accepted. It does not mean the money has arrived. Wait for the [callback](#callbacks), or check the status with [`GET /api/transactions/detail`](#transaction-status).

> [!WARNING]
>
> Always send `TransactionExternalId`, and use a new one for every payout. It becomes the payout id. If you leave it out, Pesaswap generates an id but does not return it, so you cannot look the payout up later.

### Mobile money

```bash curl theme={"system"}
curl --request POST \
  --url https://api.sandbox.pesaswap.io/api/disbursement-payment \
  --header "Authorization: {{token}}" \
  --header "Content-Type: application/json" \
  --data '{
    "MerchantIdentifier": "<your merchant identifier>",
    "Country": "KE",
    "Currency": "KES",
    "Amount": "500.00",
    "PhoneNumber": "254700000000",
    "TransactionExternalId": "payout-20001",
    "Comment": "Supplier payment",
    "Processor": "mpesa"
  }'
```

| Field | Type | Required | Description |
| - | - | - | - |
| `Country` | string | Yes | ISO 3166-1 alpha-2 country code, such as `KE`. Case does not matter. |
| `Currency` | string | Yes | ISO 4217 currency code, such as `KES`. Case does not matter. |
| `Amount` | string or number | Yes | Amount in major units. `"500.00"` and `500` both mean 500 shillings. |
| `PhoneNumber` | string | Yes | The recipient's phone number. `254700000000`, `+254700000000` and `0700000000` are all accepted. |
| `Processor` | string | Yes | `mpesa` or `coop` (both mean M-Pesa), `airtel`, or `mtn` / `momo`. Case does not matter. |
| `TransactionExternalId` | string | No | Your id for this payout. It becomes the payout id and must be unique. Always send it. |
| `Comment` | string | No | Description of the payout. |
| `MerchantIdentifier` | string | No | Accepted, not used. |

### Bank

Bank payouts use the same endpoint and the same common fields as mobile money. `PhoneNumber` is optional. The `Processor` value picks the kind of bank payout, and each kind needs its own extra fields. All bank payouts are sent through Choice Bank.

**Common fields**

| Field | Type | Required | Description |
| - | - | - | - |
| `Country` | string | Yes | ISO 3166-1 alpha-2 country code, such as `KE`. |
| `Currency` | string | Yes | ISO 4217 currency code, such as `KES`. |
| `Amount` | string or number | Yes | Amount in major units, for example `"6459.00"`. |
| `Processor` | string | Yes | `pesalink`, `paybill` or `paytill`. Case does not matter and spaces around the value are ignored. |
| `TransactionExternalId` | string | No | Your id for this payout. It becomes the payout id and must be unique. Always send it. |
| `Comment` | string | No | Description of the payout. |
| `PhoneNumber` | string | No | The recipient's phone number. Accepted so you can send the same body as for mobile money. The money goes to `AccountNumber`, not to this number. |
| `MerchantIdentifier` | string | No | Accepted, not used. |

**Fields per `Processor`**

| `Processor` | Field | Required | Description |
| - | - | - | - |
| `pesalink` | `AccountNumber` | Yes | The recipient's bank account number. |
| `pesalink` | `BankCode` | Yes | The recipient's bank, as a wire code such as `"01"`. See [Bank codes](#bank-codes). |
| `paybill` | `AccountNumber` | Yes | The M-Pesa paybill business number. |
| `paybill` | `AccountReference` | Yes | The account number at that paybill. |
| `paytill` | `AccountNumber` | Yes | The M-Pesa till number. |

A field that is missing, or sent as an empty or blank string, is rejected.

#### PesaLink example

```bash curl theme={"system"}
curl --request POST \
  --url https://api.sandbox.pesaswap.io/api/disbursement-payment \
  --header "Authorization: {{token}}" \
  --header "Content-Type: application/json" \
  --data '{
    "MerchantIdentifier": "<your merchant identifier>",
    "Country": "KE",
    "Currency": "KES",
    "Amount": "6459.00",
    "PhoneNumber": "254700000000",
    "TransactionExternalId": "payout-20002",
    "Comment": "Invoice 4471",
    "Processor": "pesalink",
    "AccountNumber": "1234567890",
    "BankCode": "01"
  }'
```

#### Paybill example

```bash curl theme={"system"}
curl --request POST \
  --url https://api.sandbox.pesaswap.io/api/disbursement-payment \
  --header "Authorization: {{token}}" \
  --header "Content-Type: application/json" \
  --data '{
    "MerchantIdentifier": "<your merchant identifier>",
    "Country": "KE",
    "Currency": "KES",
    "Amount": "6459.00",
    "PhoneNumber": "254700000000",
    "TransactionExternalId": "payout-20003",
    "Comment": "Utility bill",
    "Processor": "paybill",
    "AccountNumber": "123456",
    "AccountReference": "1234567890"
  }'
```

#### Paytill example

```bash curl theme={"system"}
curl --request POST \
  --url https://api.sandbox.pesaswap.io/api/disbursement-payment \
  --header "Authorization: {{token}}" \
  --header "Content-Type: application/json" \
  --data '{
    "MerchantIdentifier": "<your merchant identifier>",
    "Country": "KE",
    "Currency": "KES",
    "Amount": "6459.00",
    "PhoneNumber": "254700000000",
    "TransactionExternalId": "payout-20004",
    "Comment": "Shop purchase",
    "Processor": "paytill",
    "AccountNumber": "123456"
  }'
```

#### Bank codes

Use these codes in `BankCode` for `pesalink` payouts. These are the banks Choice Bank can pay.

| `BankCode` | Bank |
| - | - |
| `01` | KCB Bank Kenya |
| `02` | Standard Chartered Bank Kenya |
| `03` | Absa Bank Kenya |
| `07` | NCBA Bank Kenya |
| `10` | Prime Bank |
| `11` | Co-operative Bank of Kenya |
| `12` | National Bank of Kenya |
| `14` | M Oriental Bank |
| `16` | Citibank N.A. Kenya |
| `17` | Habib Bank AG Zurich |
| `18` | Middle East Bank Kenya |
| `19` | Bank of Africa Kenya |
| `23` | Consolidated Bank of Kenya |
| `25` | Credit Bank |
| `26` | Access Bank |
| `31` | Stanbic Bank Kenya |
| `35` | African Banking Corporation |
| `43` | Ecobank |
| `46` | Choice Microfinance Bank |
| `50` | Paramount Universal Bank |
| `51` | Kingdom Bank |
| `53` | Guaranty Trust Bank |
| `54` | Victoria Commercial Bank |
| `55` | Guardian Bank |
| `57` | I\&M Bank |
| `60` | SBM Bank Kenya |
| `61` | Housing Finance Bank |
| `63` | Diamond Trust Bank |
| `65` | Mayfair CIB Bank |
| `66` | Sidian Bank |
| `68` | Equity Bank Kenya |
| `70` | Family Bank |
| `72` | Gulf African Bank |
| `74` | Premier Bank Kenya |
| `75` | DIB Bank Kenya |
| `76` | UBA Kenya Bank |
| `78` | Kenya Women Microfinance Bank |
| `79` | Spire Bank |
| `81` | Development Bank of Kenya |
| `82` | Bank of India |
| `84` | Caritas Microfinance Bank |
| `85` | Unaitas Sacco |
| `86` | Vooma |
| `87` | Faulu Microfinance Bank |
| `88` | Gladys Technologies |

> [!NOTE]
>
> Only the codes in this table are accepted. Any other code, including the older `80` (Habib Bank AG Zurich) and `83` (Access Bank), is rejected with `Invalid BankCode`. Use `17` and `26` for those banks.

### IMT through disbursement-payment

Set `Processor` to `choice-bank-imt-rails` to send an IMT transfer to an M-Pesa account through Choice Bank. This uses its own set of fields. The amount is sent at a conversion rate of 1, in the currency you give.

```bash curl theme={"system"}
curl --request POST \
  --url https://api.sandbox.pesaswap.io/api/disbursement-payment \
  --header "Authorization: {{token}}" \
  --header "Content-Type: application/json" \
  --data '{
    "MerchantIdentifier": "<your merchant identifier>",
    "Currency": "KES",
    "Amount": 1250,
    "TransactionExternalId": "payout-20005",
    "Processor": "choice-bank-imt-rails",
    "Comment": "Family support",
    "PayeeAccountId": "254700000000",
    "PayeeAccountName": "Jane Doe"
  }'
```

| Field | Type | Required | Description |
| - | - | - | - |
| `Processor` | string | Yes | `choice-bank-imt-rails`. Case does not matter and spaces around the value are ignored. |
| `Currency` | string | Yes | ISO 4217 currency code, such as `KES`. |
| `Amount` | string or number | Yes | Amount in major units. |
| `PayeeAccountId` | string | Yes | The recipient's M-Pesa account. |
| `PayeeAccountName` | string | Yes | The recipient's name. |
| `TransactionExternalId` | string | No | Your id for this payout. `TransactionExternalID` is also accepted. It becomes the payout id and must be unique. Always send it. |
| `Comment` | string | No | Purpose of the transfer. If empty, `IMT Rails Transfer` is sent. |
| `MerchantIdentifier` | string | No | Accepted, not used. |

Other fields, such as `PhoneNumber`, `Country`, `PayeeBankCode` or `PayeeType`, are ignored for this `Processor`. To send the sender's details and a conversion rate, use [`POST /api/choice-bank/imt-rails-transfer`](#imt-transfer) instead.

### Payout errors

All errors have the body `{"error":"<message>"}`.

| Status | Message | Cause | What to do |
| - | - | - | - |
| `400` | `Missing required field: Processor.` | `Processor` is not one of the accepted values. | Fix `Processor`. |
| `400` | `Missing required field: AccountNumber.` | A bank payout without `AccountNumber`, or with a blank one. The same message names `BankCode` or `AccountReference` when one of those is missing. | Send the field. |
| `400` | `Invalid BankCode: <code>` | `BankCode` is not one of the codes in [Bank codes](#bank-codes). | Use a code from [Bank codes](#bank-codes). |
| `400` | `Invalid request body: <detail>` | The body is not valid JSON, a mobile or IMT field is missing, or a value such as `Currency` is not recognised. `<detail>` says which. | Fix the body. |
| `400` | `Insufficient funds.` | Your Pesaswap wallet does not hold enough for this payout. | Top up, then send again with a **new** `TransactionExternalId`. |
| `400` | `Duplicate ExternalId.` | A payout with this `TransactionExternalId` already exists. | Do not resend. Check the existing payout's status. |
| `401` | `Invalid Credentials. Please Check your consumer_key and api_key.` | See [Authentication](#authentication). | Get a new token. |
| `503` | `Bank temporarily unavailable. Transaction not sent, please retry.` | Pesaswap could not reach the provider. Nothing was sent and your wallet was not debited. | Retry with a **new** `TransactionExternalId`. |
| `500` | `Internal server error.` | Any other failure. | Check the payout's status before you send it again. |

> [!WARNING]
>
> A payout rejected with `Insufficient funds.` or the `503` error is still recorded, as failed, under its `TransactionExternalId`. Sending the same id again returns `Duplicate ExternalId.` Use a new id for the retry.

> [!WARNING]
>
> After a `500` the payout may or may not have been sent. Look it up with [`GET /api/transactions/detail`](#transaction-status) before you try again, or you risk paying twice.

## IMT transfer

`POST /api/choice-bank/imt-rails-transfer` sends an IMT payout to an M-Pesa account through Choice Bank, with the sender's details and a conversion rate.

```bash curl theme={"system"}
curl --request POST \
  --url https://api.sandbox.pesaswap.io/api/choice-bank/imt-rails-transfer \
  --header "Authorization: {{token}}" \
  --header "Content-Type: application/json" \
  --data '{
    "MerchantIdentifier": "<your merchant identifier>",
    "TransactionExternalId": "imt-30001",
    "PayeeAccountName": "Jane Doe",
    "PayeeAccountId": "254700000000",
    "ImtSenderName": "John Doe",
    "ImtSenderPhoneNumber": "254700000001",
    "ImtSenderServiceProvider": "<sender service provider>",
    "ImtForeignCurrency": "KES",
    "ImtConversionRate": "1",
    "Amount": "1000.00",
    "Currency": "KES",
    "Comment": "Family support"
  }'
```

| Field | Type | Required | Description |
| - | - | - | - |
| `PayeeAccountName` | string | Yes | The recipient's name. |
| `PayeeAccountId` | string | Yes | The recipient's M-Pesa account. |
| `ImtSenderName` | string | Yes | The sender's name. |
| `ImtSenderPhoneNumber` | string | Yes | The sender's phone number. |
| `ImtSenderServiceProvider` | string | Yes | The service provider the sender used. |
| `ImtForeignCurrency` | string | Yes | ISO 4217 currency code. The payout is recorded in this currency. |
| `ImtConversionRate` | string | Yes | The conversion rate, passed to Choice Bank as given. |
| `Amount` | string or number | Yes | Amount in major units. This is also sent as the original amount. |
| `Currency` | string | Yes | ISO 4217 currency code of `Amount`. |
| `TransactionExternalId` | string | No | Your id for this payout. It becomes the payout id and must be unique. Always send it. |
| `Comment` | string | No | Purpose of the transfer. If empty, `IMT Rails Transfer` is sent. |
| `ImtSenderNationality` | string | No | Accepted, not used. Choice Bank is always sent `KEN`. |
| `ImtFundsOriginCountryCode` | string | No | Accepted, not used. Choice Bank is always sent `KEN`. |
| `MerchantIdentifier` | string | No | Accepted, not used. |

**Response `200`**

```json theme={"system"}
{ "Response": "Success. Request accepted for processing" }
```

**Errors**

The same as [Payout errors](#payout-errors), except that a malformed body or a missing field returns `400` with `{"error":{"error_type":"invalid_request","message":"...","code":"IR_06"}}`.

## Transaction status

Status is reported as a number in `/detail` and as text in `/list` and in callbacks:

| Code | Text | Meaning |
| - | - | - |
| `1` | `Completed` | The money moved. |
| `2` | `Failed` | The transaction failed, was cancelled or expired. No money moved. |
| `3` | `Pending` | Still in progress. Check again later or wait for the callback. |

### Transaction detail

`GET /api/transactions/detail` returns one collection or payout by its `TransactionExternalId`. It looks for a collection first, then a payout. Pesaswap asks the provider for the latest status during the call.

```bash curl theme={"system"}
curl --request GET \
  --url "https://api.sandbox.pesaswap.io/api/transactions/detail?TransactionExternalId=payout-20002" \
  --header "Authorization: {{token}}"
```

| Parameter | Type | Required | Description |
| - | - | - | - |
| `TransactionExternalId` | string | Yes | The id you sent when you created the collection or payout. |

**Response `200`**

```json theme={"system"}
{
  "TransactionExternalId": "payout-20002",
  "MpesaTransactionId": "TK1AB2CD3E",
  "Status": 1,
  "Amount": 6459.0,
  "Currency": "KES",
  "Processor": "ChoiceBank",
  "Remarks": "Invoice 4471"
}
```

| Field | Description |
| - | - |
| `TransactionExternalId` | Your id. |
| `MpesaTransactionId` | The provider's reference, when there is one. Left out otherwise. |
| `Status` | `1`, `2` or `3`. See the table above. |
| `Amount` | Amount in major units, as a number. |
| `Currency` | ISO 4217 currency code. |
| `Processor` | `Mpesa`, `Airtel`, `momo`, `ChoiceBank` or `Unknown`. |
| `Remarks` | For a collection, its description. For a payout, the failure reason if there is one, otherwise its description. Left out if empty. |

If the provider cannot be reached during the call, a payout is returned with the last status Pesaswap holds.

**Errors**

| Status | Body | Cause |
| - | - | - |
| `400` | `{"error":"Missing required field: TransactionExternalId."}` | `TransactionExternalId` is missing. |
| `400` | `{"error":"Transaction not found."}` | No collection or payout has this id. Refund ids are not found here. |
| `401` | `{"error":"Invalid Credentials. Please Check your consumer_key and api_key."}` | See [Authentication](#authentication). |
| `500` | `{"error":"Internal server error."}` | Any other failure. |

> [!NOTE]
>
> "Not found" returns status `400`, not `404`.

### List transactions

`GET /api/transactions/list` returns collections, refunds and payouts. It takes a JSON body on a `GET` request, as the old platform did.

```bash curl theme={"system"}
curl --request GET \
  --url https://api.sandbox.pesaswap.io/api/transactions/list \
  --header "Authorization: {{token}}" \
  --header "Content-Type: application/json" \
  --data '{
    "MerchantIdentifier": "<your merchant identifier>",
    "FromDate": "2026-11-01",
    "ToDate": "2026-11-24",
    "Status": 1,
    "Skip": 0,
    "Take": 50
  }'
```

| Field | Type | Required | Description |
| - | - | - | - |
| `FromDate` | string | Yes, unless `TransactionExternalId` is sent | Start date, `YYYY-MM-DD`, from 00:00:00 UTC. |
| `ToDate` | string | Yes, unless `TransactionExternalId` is sent | End date, `YYYY-MM-DD`, up to 23:59:59 UTC. The day is included. |
| `TransactionExternalId` | string | No | Return only this collection or payout, and ignore the dates. `transactionExternalId` is also accepted. |
| `Status` | integer | No | Only return transactions with this status: `1`, `2` or `3`. |
| `Skip` | integer | No | Number of results to skip. Defaults to `0`. |
| `Take` | integer | No | Number of results to return. `0` or missing returns all. |
| `MerchantIdentifier` | string | No | Accepted, not used. |

Results are sorted newest first. For a date range, at most 100 collections, 100 refunds and 100 payouts are read, and `Skip` and `Take` apply after that. If you have more than that in a range, use a shorter range.

**Response `200`**

```json theme={"system"}
{
  "count": 1,
  "result": [
    {
      "transactionExternalId": "payout-20002",
      "transactionId": "TK1AB2CD3E",
      "businessName": "Example Ltd",
      "utilityFunds": null,
      "workingFunds": null,
      "type": "disbursement",
      "status": "Completed",
      "description": "Invoice 4471",
      "amount": 6459.0,
      "currency": "KES",
      "gatewayFee": 0.0,
      "processorFee": 0.0,
      "totalFee": 0.0,
      "customer": "Customer",
      "mpesaCustomer": null,
      "method": "ChoiceBank",
      "phone": null,
      "dateCreated": "2026-11-24T07:15:02",
      "eaDate": "2026-11-24T10:15:02"
    }
  ]
}
```

| Field | Description |
| - | - |
| `count` | Number of items in `result` (after `Skip` and `Take`). It is not the total for the range. |
| `transactionExternalId` | Your id for the collection, refund or payout. |
| `transactionId` | The provider's reference, or `null`. |
| `businessName` | Your business name. |
| `type` | `sales` (collection), `refund` or `disbursement` (payout). |
| `status` | `Completed`, `Failed` or `Pending`. |
| `description` | For a failed refund or payout, the failure reason. Otherwise the description you sent. |
| `amount` | Amount in major units, as a number. |
| `currency` | ISO 4217 currency code. |
| `customer` | Customer name if known, otherwise an empty string. |
| `method` | `Mpesa`, `Airtel`, `momo`, `ChoiceBank` or `Unknown`. |
| `phone` | Customer phone if known, otherwise `null`. |
| `dateCreated` | Creation time in UTC. |
| `eaDate` | Creation time in East Africa Time (UTC+3). |
| `utilityFunds`, `workingFunds`, `mpesaCustomer` | Always `null`. Kept for compatibility. |
| `gatewayFee`, `processorFee`, `totalFee` | Always `0`. Kept for compatibility. |

**Errors**

| Status | Body | Cause |
| - | - | - |
| `400` | `{"error":"Missing required field: FromDate."}` | `FromDate` is missing or not in `YYYY-MM-DD` format. |
| `400` | `{"error":"Missing required field: ToDate."}` | `ToDate` is missing or not in `YYYY-MM-DD` format. |
| `400` | `{"error":{"error_type":"invalid_request","message":"...","code":"IR_06"}}` | The body is not valid JSON, or `Content-Type: application/json` is missing. |
| `401` | `{"error":"Invalid Credentials. Please Check your consumer_key and api_key."}` | See [Authentication](#authentication). |

A `TransactionExternalId` that matches nothing returns `200` with `"count": 0`.

## Callbacks

When a collection or payout changes status, Pesaswap calls your callback URL. Pesaswap sets the callback URL on your account.

The callback is an HTTP `GET` request. The payload is a JSON object, URL-encoded, in the `data` query parameter:

```
GET https://your-server.example.com/callback?data=%7B%22id%22%3A2611266102...
```

Decoded, `data` looks like this:

```json theme={"system"}
{
  "id": 2611266102,
  "business_name": "Example Ltd",
  "transaction_external_id": "payout-20002",
  "transaction_id": "TK1AB2CD3E",
  "amount": "6459.00",
  "status": "Completed",
  "mpesa_result_desc": null,
  "processor": "mpesa",
  "method": "choicebank-m-pesa",
  "command_id": null,
  "customer": null,
  "send_to_callback_url": "https://your-server.example.com/callback",
  "transaction_type": "payout",
  "result_desc": null
}
```

| Field | Description |
| - | - |
| `id` | A number built from the date and time the callback was made. It is not unique. Do not use it as a key. |
| `business_name` | Your business name, or your merchant identifier if no name is set. |
| `transaction_external_id` | Your `TransactionExternalId`. Use this to match the callback to your transaction. |
| `transaction_id` | The provider's transaction id, or `null`. |
| `amount` | Amount in major units, as a string with two decimals. |
| `status` | `Completed`, `Failed` or `Pending`. |
| `mpesa_result_desc` | The failure reason, or `null`. |
| `result_desc` | The same as `mpesa_result_desc`. |
| `processor` | `mpesa`, `airtel`, `mtn` or `unknown`. Choice Bank payouts show `mpesa`, including bank payouts (`pesalink`, `paybill`, `paytill`). Match callbacks on `transaction_external_id`, not on `processor`. |
| `method` | For collections: `airtel collection`, `choicebank-m-pesa` or `OP`. For payouts: `airtel disbursement`, `choicebank-m-pesa` or `B2C`. |
| `transaction_type` | `sale` (collection) or `payout`. |
| `send_to_callback_url` | The URL this callback was sent to. |
| `command_id`, `customer` | Always `null`. |

> [!NOTE]
>
> Callback field names are snake\_case, unlike the PascalCase request fields.

### Verify a callback

Each callback carries an `Authorization` header, and a `Signature` header if a signing key is set up for your account. The keys used below are set up on your account by Pesaswap. `consumer_key` is your merchant identifier.

**`Authorization`** is `Basic ` followed by base64 of one of these, depending on how your account is set up:

* `consumer_key:api_key`
* `consumer_key:api_key:transaction_external_id:amount` (extended mode)

**`Signature`** is a lowercase hex SHA-256 digest, built like this:

1. `auth = base64(consumer_key + api_key + signing_key)`
2. `body = base64(id + transaction_external_id + amount + status + processor)`, using the values from `data` exactly as sent (`id` as decimal digits, `amount` with two decimals)
3. `Signature = hex(sha256(auth + body))`

There are no separators between the joined values. Compute the signature on your side and compare it with the header. Reject the callback if they differ.

```javascript Node.js theme={"system"}
const crypto = require("crypto");

function verifyPesaswapCallback(query, headers, consumerKey, apiKey, signingKey) {
  const data = JSON.parse(query.data);
  const b64 = (s) => Buffer.from(s, "utf8").toString("base64");

  const auth = b64(consumerKey + apiKey + signingKey);
  const body = b64(
    String(data.id) + data.transaction_external_id + data.amount + data.status + data.processor
  );
  const expected = crypto.createHash("sha256").update(auth + body).digest("hex");

  const received = headers["signature"] || "";
  return (
    received.length === expected.length &&
    crypto.timingSafeEqual(Buffer.from(received), Buffer.from(expected))
  );
}
```

```python Python theme={"system"}
import base64
import hashlib
import hmac
import json


def verify_pesaswap_callback(query, headers, consumer_key, api_key, signing_key):
    data = json.loads(query["data"])
    b64 = lambda s: base64.b64encode(s.encode("utf-8")).decode("ascii")

    auth = b64(consumer_key + api_key + signing_key)
    body = b64(
        str(data["id"])
        + data["transaction_external_id"]
        + data["amount"]
        + data["status"]
        + data["processor"]
    )
    expected = hashlib.sha256((auth + body).encode("utf-8")).hexdigest()

    return hmac.compare_digest(headers.get("Signature", ""), expected)
```

## Errors

Errors from these endpoints use this shape:

```json theme={"system"}
{ "error": "<message>" }
```

| Status | Message | When |
| - | - | - |
| `400` | `Missing required field: <field>.` | A required field is missing. On `/api/collection-payment` and `/api/disbursement-payment`, also an unknown `Processor`. On `/api/transactions/list`, also a date not in `YYYY-MM-DD` format. |
| `400` | `Duplicate ExternalId.` | A collection, refund or payout with this id already exists. |
| `400` | `Transaction not found.` | No transaction has this id. |
| `400` | `Insufficient funds.` | Your wallet does not hold enough for the payout. |
| `400` | `Invalid Processor: <value>.` | `/api/balance/v2` only. Unknown `Processor`. |
| `400` | `Invalid BankCode: <code>` | Bank payouts only. Unknown `BankCode`. |
| `400` | `Invalid request body: <detail>` | `/api/disbursement-payment` only. The body could not be read. |
| `401` | `Invalid Credentials. Please Check your consumer_key and api_key.` | Wrong credentials, or a missing, invalid or expired token. |
| `503` | `Bank temporarily unavailable. Transaction not sent, please retry.` | Payouts only. The provider could not be reached and nothing was sent. |
| `500` | `Internal server error.` | Any other failure. |

On every endpoint except `/api/disbursement-payment`, a body that is not valid JSON, has a missing or wrongly typed field, or is sent without `Content-Type: application/json` is rejected before it reaches the legacy handler. That error has a different shape:

```json theme={"system"}
{
  "error": {
    "error_type": "invalid_request",
    "message": "Json deserialize error: missing field `phone_number` at line 1 column 120",
    "code": "IR_06"
  }
}
```

The `message` names fields in snake\_case (`phone_number`), not in the PascalCase you send.


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