daraja-openapi

API reference / Account Balance

Read your shortcode's balances

POST/mpesa/accountbalance/v1/query

Checked against the Safaricom sandbox on 1 December 2026

Requests the balances of your shortcode's accounts. They arrive at ResultURL in the AccountBalance result parameter, as Name|Currency|Amount|Reserved|Uncleared|Locked groups separated by &.

In the SDKs

SDKMethod
TypeScriptaccountBalance()
Pythonaccount_balance()
PHPaccountBalance()
KotlinaccountBalance()
SwiftaccountBalance()

Request

EnvironmentURL
Sandboxhttps://sandbox.safaricom.co.ke/mpesa/accountbalance/v1/query
Productionhttps://api.safaricom.co.ke/mpesa/accountbalance/v1/query

Send the access token as Authorization: Bearer <token>, and the body as JSON.

FieldTypeDescription
InitiatorstringRequiredThe API operator created on the M-PESA org portal. testapi in the sandbox.
SecurityCredentialstringRequiredThe initiator's password encrypted with Safaricom's public certificate (RSA, PKCS #1 v1.5 padding), base64-encoded. The sandbox and production use different certificates.
CommandIDstringRequiredAlways AccountBalance.
PartyAstringRequiredA paybill or till number. Matches ^[0-9]{5,7}$.
IdentifierTypestringRequiredOne of 2, 4.
RemarksstringRequired2–100 characters.
QueueTimeOutURLstring (uri)RequiredMatches ^https://.
ResultURLstring (uri)RequiredMatches ^https://.

Example request

curl -X POST "https://sandbox.safaricom.co.ke/mpesa/accountbalance/v1/query" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "Initiator": "testapi",
  "SecurityCredential": "EsJocK7+NjqZPC3I3EO+TbvS+xVb9TymWwaKABoaZr/Z/n0UysSs..",
  "CommandID": "AccountBalance",
  "PartyA": "600984",
  "IdentifierType": "4",
  "Remarks": "Daily balance",
  "QueueTimeOutURL": "https://example.com/mpesa/balance/timeout",
  "ResultURL": "https://example.com/mpesa/balance/result"
}'

Response

Daraja queued the request. This is not the outcome: that arrives at ResultURL.

FieldTypeDescription
ConversationIDstringRequired
OriginatorConversationIDstringRequired
ResponseCodestringRequired"0" means Daraja queued the request. The outcome comes to ResultURL.
ResponseDescriptionstringRequired

Errors

StatusMeaning
400Daraja rejected the request. An HTTP 401 with "Invalid API call as no apiproduct match found" means your Daraja app does not have this API product enabled: add it to the app on the Daraja portal, then request a new access token.
401Daraja rejected the request. An HTTP 401 with "Invalid API call as no apiproduct match found" means your Daraja app does not have this API product enabled: add it to the app on the Daraja portal, then request a new access token.
500Daraja rejected the request. An HTTP 401 with "Invalid API call as no apiproduct match found" means your Daraja app does not have this API product enabled: add it to the app on the Daraja portal, then request a new access token.

See errors and rate limits for what to do with each.

Example response

{
  "ConversationID": "AG_20261201_2010325b025970fbc403",
  "OriginatorConversationID": "6f2b8c1e-3c1d-4a8e-9a55-0d1bc7a2f001",
  "ResponseCode": "0",
  "ResponseDescription": "Accept the service request successfully."
}

Callbacks

Daraja calls these on your server. They are not signed: confirm with Daraja before you act on one. See handling callbacks.

The result of a B2C, B2B, reversal, status or balance request

Sent to ResultURL from your request.

ResultCode 0 means the request succeeded. Details arrive as key/value pairs in ResultParameters, which is missing when the request failed. Not signed: match it to your request by OriginatorConversationID and ConversationID, and answer HTTP 200.

FieldTypeDescription
ResultobjectRequired
Result.ResultTypeintegerRequired
Result.ResultCodeinteger or stringRequired0 means success. Some APIs send it as a string.
Result.ResultDescstringRequired
Result.OriginatorConversationIDstringRequired
Result.ConversationIDstringRequired
Result.TransactionIDstring
Result.ResultParametersobject
Result.ResultParameters.ResultParameterarray of object or objectOne item or a list, depending on the API.
Result.ResultParameters.ResultParameter[].KeystringRequired
Result.ResultParameters.ResultParameter[].Valuestring or number
Result.ReferenceDataobject
Result.ReferenceData.ReferenceItemarray of object or object
Result.ReferenceData.ReferenceItem[].KeystringRequired
Result.ReferenceData.ReferenceItem[].Valuestring or number

Example body

{
  "Result": {
    "ResultType": 0,
    "ResultCode": 0,
    "ResultDesc": "The service request is processed successfully.",
    "OriginatorConversationID": "6f2b8c1e-3c1d-4a8e-9a55-0d1bc7a2f001",
    "ConversationID": "AG_20261201_2010325b025970fbc403",
    "TransactionID": "TKU3XXXXXX",
    "ResultParameters": {
      "ResultParameter": [
        {
          "Key": "TransactionAmount",
          "Value": 100
        },
        {
          "Key": "TransactionReceipt",
          "Value": "TKU3XXXXXX"
        },
        {
          "Key": "ReceiverPartyPublicName",
          "Value": "254708374149 - John Doe"
        }
      ]
    },
    "ReferenceData": {
      "ReferenceItem": {
        "Key": "QueueTimeoutURL",
        "Value": "https://internalsandbox.safaricom.co.ke/mpesa/b2cresults/v1/submit"
      }
    }
  }
}

The request timed out in M-PESA's queue

Sent to QueueTimeOutURL from your request.

M-PESA could not process the request in time. Its outcome is unknown: check with the Transaction Status query before retrying a payment.

FieldTypeDescription
ResultobjectRequired
Result.ResultTypeintegerRequired
Result.ResultCodeinteger or stringRequired0 means success. Some APIs send it as a string.
Result.ResultDescstringRequired
Result.OriginatorConversationIDstringRequired
Result.ConversationIDstringRequired
Result.TransactionIDstring
Result.ResultParametersobject
Result.ResultParameters.ResultParameterarray of object or objectOne item or a list, depending on the API.
Result.ResultParameters.ResultParameter[].KeystringRequired
Result.ResultParameters.ResultParameter[].Valuestring or number
Result.ReferenceDataobject
Result.ReferenceData.ReferenceItemarray of object or object
Result.ReferenceData.ReferenceItem[].KeystringRequired
Result.ReferenceData.ReferenceItem[].Valuestring or number

View the source of this page

Built by ByteGigs Labs. Apache 2.0. M-PESA, Daraja and Safaricom are trademarks of Safaricom PLC; this project is independent and not endorsed by Safaricom.