Account Balance
By the end of this track you can find out what happened and undo it.
0/3 finished
Step 1
The idea
Your shortcode's balance, delivered to your ResultURL.
Step 2
How it works
The request
POST to /mpesa/accountbalance/v1/query. Identifier type 4 is a shortcode.
{ "Initiator": "testapi", "SecurityCredential": "<encrypted password>", "CommandID": "AccountBalance", "PartyA": "600996", "IdentifierType": "4", "Remarks": "Daily balance", "QueueTimeOutURL": "https://your-domain.example/balance/timeout", "ResultURL": "https://your-domain.example/balance/result"}Reading the result
The result has a AccountBalance parameter: one string listing each account. Split it on & to get the accounts, then on | to get the account name, the currency and its balance figures. The kit's callback parser does this for you.
Working Account|KES|46713.00|46713.00|0.00|0.00&Utility Account|KES|1500.00|1500.00|0.00|0.00Using it
Check the B2C (utility) account before a batch of payouts so it doesn't fail halfway, and record the balance each day for reconciliation (lesson D3).
Step 3
Try it
$ mpesa balance
With the MCP server, ask your agent to use mpesa_account_balance
Step 4
Common mistakes
- Polling the balance constantly. Once before payouts and once a day is plenty.
Go deeper
How does the balance help reconciliation?
Answer in your own words first.
Show the answerHide the answer
The day's change should equal the day's ledger total.