Skip to main content
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. All examples below use the sandbox URL.
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.
Response 200
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

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.
A missing, invalid or expired token returns:
with status 401. An API key that is revoked or expires after you got the token also makes the token stop working.
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.
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
This means the request was accepted. It does not mean the customer has paid. Wait for the callback, or check the status with GET /api/transactions/detail. Errors

Refunds

POST /api/refund refunds a collection in full.
There is no amount field. The full amount of the collection is refunded. Response 200
Errors
Refunds do not show up in GET /api/transactions/detail. To see a refund’s status, use GET /api/transactions/list 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

GET /api/balance

Response 200
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

Response 200
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
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.
Response 200
  • 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

Payouts

POST /api/disbursement-payment sends money from your Pesaswap wallet. The Processor field decides where it goes:
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
This means the payout was accepted. It does not mean the money has arrived. Wait for the callback, or check the status with GET /api/transactions/detail.
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

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 Fields per Processor A field that is missing, or sent as an empty or blank string, is rejected.

Paybill example

Paytill example

Bank codes

Use these codes in BankCode for pesalink payouts. These are the banks Choice Bank can pay.
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.
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 instead.

Payout errors

All errors have the body {"error":"<message>"}.
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.
After a 500 the payout may or may not have been sent. Look it up with GET /api/transactions/detail 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.
Response 200
Errors The same as 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:

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.
Response 200
If the provider cannot be reached during the call, a payout is returned with the last status Pesaswap holds. Errors
“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.
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
Errors 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:
Decoded, data looks like this:
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.

Errors

Errors from these endpoints use this shape:
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:
The message names fields in snake_case (phone_number), not in the PascalCase you send.