Appearance
Retrieve an account's balance
Reads what one of your accounts holds, wallet by wallet: main first, then any pockets the owner made.
In pocket mode (your platform has a pocket set up by MOOKHPay), it reads only your platform's pocket in the person's wallet, never main or their other pockets. See Pocket mode.
It reads the ledger as it stands now. There is no pending or reserved split: money reserved for a payout in flight has already left the balance.
Endpoint
GET /v1/payments/merchant/accounts/{id}/balance| Auth | Secret key, Authorization: Bearer mkp_… |
| Scope | accounts:read on the key, and accounts:read in the account's grant |
| Platform | The key's organisation must be an active platform, and the call must come from an address on its allow-list if it has one |
| Feature flag | Registered only where the platform API is on |
Headers
| Header | Required | Value |
|---|---|---|
Authorization | Yes | Bearer mkp_test_… or Bearer mkp_live_… |
Parameters
Path
| Name | Type | Required | Constraints and meaning |
|---|---|---|---|
id | string | Yes | One of your account ids, acct_<country>_<24 hex> |
Example request
sh
curl https://payments-ke-staging.mookhpay.co/v1/payments/merchant/accounts/acct_ke_9c2f41b07e5d38a6c1f0b294/balance \
-H "Authorization: Bearer $MOOKHPAY_SECRET_KEY"js
const BASE = "https://payments-ke-staging.mookhpay.co/v1/payments/merchant";
const id = "acct_ke_9c2f41b07e5d38a6c1f0b294";
const res = await fetch(`${BASE}/accounts/${id}/balance`, {
headers: { Authorization: `Bearer ${process.env.MOOKHPAY_SECRET_KEY}` },
});
const body = await res.json();
if (!body.ok) throw new Error(`${res.status} ${body.code}: ${body.description}`);
// In pocket mode, `available` is the pocket. Otherwise read `main`.
const balance =
body.data.available ?? body.data.wallets.find((w) => w.wallet === "main").balance;
console.log(`${body.data.currency} ${(balance / 100).toFixed(2)}`);python
import os
import requests
BASE = "https://payments-ke-staging.mookhpay.co/v1/payments/merchant"
account_id = "acct_ke_9c2f41b07e5d38a6c1f0b294"
res = requests.get(
f"{BASE}/accounts/{account_id}/balance",
headers={"Authorization": f"Bearer {os.environ['MOOKHPAY_SECRET_KEY']}"},
timeout=30,
)
body = res.json()
if not body["ok"]:
raise RuntimeError(f"{res.status_code} {body['code']}: {body['description']}")
data = body["data"]
# In pocket mode, `available` is the pocket. Otherwise read `main`.
if "available" in data:
balance = data["available"]
else:
balance = next(w for w in data["wallets"] if w["wallet"] == "main")["balance"]
print(f"{data['currency']} {balance / 100:.2f}")php
<?php
$base = "https://payments-ke-staging.mookhpay.co/v1/payments/merchant";
$id = "acct_ke_9c2f41b07e5d38a6c1f0b294";
$ch = curl_init("$base/accounts/$id/balance");
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ["Authorization: Bearer " . getenv("MOOKHPAY_SECRET_KEY")],
]);
$body = json_decode(curl_exec($ch), true);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);
if (!$body["ok"]) {
throw new RuntimeException("$status {$body['code']}: {$body['description']}");
}
foreach ($body["data"]["wallets"] as $wallet) {
printf("%s %s %.2f\n", $wallet["wallet"], $body["data"]["currency"], $wallet["balance"] / 100);
}Response
200 OK with description Balance. Without a pocket:
json
{
"ok": true,
"description": "Balance",
"data": {
"account": "acct_ke_9c2f41b07e5d38a6c1f0b294",
"currency": "KES",
"total": 1285000,
"wallets": [
{ "wallet": "main", "name": "Main", "balance": 1235000 },
{ "wallet": "rent", "name": "Rent", "balance": 50000 }
]
}
}Response fields
| Field | Type | Meaning |
|---|---|---|
account | string | The account id |
currency | string or null | KES or UGX, from the host. null only on a deployment with no mobile-money rail switched on |
total | integer | Minor units, every wallet added together |
wallets | array | One entry per wallet, main first |
wallets[].wallet | string | main, or a pocket's slug. Pass it as wallet to List an account's transactions |
wallets[].name | string | The wallet's name as the owner sees it |
wallets[].balance | integer | Minor units. The ledger keeps whole currency units, so this is always a multiple of 100 |
pocket | object | Pocket mode only. { slug, name } of your platform's pocket |
available | integer | Pocket mode only. Minor units. The pocket's balance: what you can pay out, less the payout fee |
Without a pocket, payments you take for a seller and payouts you make move only main. The seller's own pockets are theirs; you can read them, but no route moves money into or out of them.
Pocket mode
When your platform has a pocket set up, the answer is about that pocket only:
json
{
"ok": true,
"description": "Balance",
"data": {
"account": "acct_ke_9c2f41b07e5d38a6c1f0b294",
"currency": "KES",
"pocket": { "slug": "kazi", "name": "Kazi Studio" },
"available": 150000,
"total": 150000,
"wallets": [{ "wallet": "kazi", "name": "Kazi Studio", "balance": 150000 }]
}
}availableandtotalare both the pocket's balance, andwalletsholds only the pocket.- Money moves into the pocket by your pay-ins and out by your payouts. The person can also move, spend or withdraw it in MOOKHPay at any time: it is their money.
- If the pocket is still being opened, the call answers
409with code3063. If the person disconnected your platform, it answers409with code3061.
Errors
| HTTP | Code | Name | When | What to do |
|---|---|---|---|---|
400 | 3014 | IDENTITY_HEADER_REFUSED | The request carries a session or identity header | Remove the header |
401 | 2781 | API_KEY_INVALID | Missing, malformed, unknown or revoked key | Check the key |
403 | 2941 | API_KEY_SCOPE_REQUIRED | The key lacks accounts:read | Issue a key with the scope |
403 | 3042 | API_KEY_IP_NOT_ALLOWED | The account has allowed addresses and the call came from another address | Call from a listed address |
403 | 2942 | PLATFORM_NOT_ENABLED | The organisation is not an active platform | Ask MOOKHPay |
403 | 3013 | PLATFORM_IP_NOT_ALLOWED | The call came from an address not on your allow-list | Call from a listed address |
403 | 3025 | PLATFORM_GRANT_SCOPE_MISSING | The account's grant does not include accounts:read | Ask the owner to approve a new account link with accounts:read |
404 | 2943 | PLATFORM_ACCOUNT_NOT_FOUND | Unknown, another platform's, revoked or malformed id | Check the id |
409 | 3061 | PLATFORM_ACCOUNT_DISCONNECTED | Where pockets are available (Kenya): the person disconnected your platform in MOOKHPay. data.error is PLATFORM_ACCOUNT_DISCONNECTED | Stop showing a live balance. Ask them to connect again |
409 | 3063 | PLATFORM_POCKET_NOT_READY | Pocket mode: the pocket is still being opened. data.error is PLATFORM_POCKET_NOT_READY | Retry in a minute |
429 | 1804 | RATE_LIMIT_EXCEEDED | Over the rate limit, or over 100 unknown account ids in an hour | Wait Retry-After seconds |
503 | 2752 | LEDGER_UNAVAILABLE | The ledger did not answer | Retry with backoff |
503 | 2782 | AUTHN_UNAVAILABLE | Keys cannot be checked | Retry with backoff |
503 | 3016 | PLATFORM_ACCOUNTS_UNAVAILABLE | The account, or in pocket mode its pocket, could not be read | Retry with backoff |
Rate limit
120 requests a minute per platform, shared with every other account route. Over it: 429, code 1804, Retry-After in seconds. To show many sellers' balances, cache them and refresh on the webhooks that change them (payment.succeeded, payout.paid, payout.failed) rather than reading every account on every page view. In pocket mode, your own pay-ins change it too.