API reference / B2B
Pay another business's paybill or till
/mpesa/b2b/v1/paymentrequestChecked against the Safaricom sandbox on 1 December 2026
Moves money from your shortcode to another business: a supplier's paybill
(BusinessPayBill) or till (BusinessBuyGoods). The result arrives at
ResultURL. Daraja spells RecieverIdentifierType this way.
In the SDKs
| SDK | Method |
|---|---|
| TypeScript | b2bPayment() |
| Python | b2b_payment() |
| PHP | b2bPayment() |
| Kotlin | b2bPayment() |
| Swift | Through the generated client: daraja.raw.b2bPayment() |
Request
| Environment | URL |
|---|---|
| Sandbox | https://sandbox.safaricom.co.ke/mpesa/b2b/v1/paymentrequest |
| Production | https://api.safaricom.co.ke/mpesa/b2b/v1/paymentrequest |
Send the access token as Authorization: Bearer <token>, and the body as JSON.
| Field | Type | Description |
|---|---|---|
Initiator | stringRequired | The API operator created on the M-PESA org portal. testapi in the sandbox. |
SecurityCredential | stringRequired | The initiator's password encrypted with Safaricom's public certificate (RSA, PKCS #1 v1.5 padding), base64-encoded. The sandbox and production use different certificates. |
CommandID | stringRequired | One of BusinessPayBill, BusinessBuyGoods. |
SenderIdentifierType | stringRequired | "4" for a shortcode. Always 4. |
RecieverIdentifierType | stringRequired | Spelled this way by Daraja. Always 4. |
Amount | integerRequired | At least 1. |
PartyA | stringRequired | A paybill or till number. Matches ^[0-9]{5,7}$. |
PartyB | stringRequired | A paybill or till number. Matches ^[0-9]{5,7}$. |
AccountReference | stringRequired | 1–13 characters. |
Requester | string | A Kenyan mobile number in international format without the plus, e.g. 254708374149. Matches ^254(7|1)[0-9]{8}$. |
Remarks | stringRequired | 2–100 characters. |
QueueTimeOutURL | string (uri)Required | Matches ^https://. |
ResultURL | string (uri)Required | Matches ^https://. |
Occassion | string |
Example request
curl -X POST "https://sandbox.safaricom.co.ke/mpesa/b2b/v1/paymentrequest" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"Initiator": "testapi",
"SecurityCredential": "EsJocK7+NjqZPC3I3EO+TbvS+xVb9TymWwaKABoaZr/Z/n0UysSs..",
"CommandID": "BusinessPayBill",
"SenderIdentifierType": "4",
"RecieverIdentifierType": "4",
"Amount": 1000,
"PartyA": "600992",
"PartyB": "600000",
"AccountReference": "SUP-2201",
"Requester": "254708374149",
"Remarks": "Stock for December",
"QueueTimeOutURL": "https://example.com/mpesa/b2b/timeout",
"ResultURL": "https://example.com/mpesa/b2b/result"
}'Response
Daraja queued the request. This is not the outcome: that arrives at ResultURL.
| Field | Type | Description |
|---|---|---|
ConversationID | stringRequired | |
OriginatorConversationID | stringRequired | |
ResponseCode | stringRequired | "0" means Daraja queued the request. The outcome comes to ResultURL. |
ResponseDescription | stringRequired |
Errors
| Status | Meaning |
|---|---|
400 | Daraja 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. |
401 | Daraja 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. |
500 | Daraja 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.
| Field | Type | Description |
|---|---|---|
Result | objectRequired | |
Result.ResultType | integerRequired | |
Result.ResultCode | integer or stringRequired | 0 means success. Some APIs send it as a string. |
Result.ResultDesc | stringRequired | |
Result.OriginatorConversationID | stringRequired | |
Result.ConversationID | stringRequired | |
Result.TransactionID | string | |
Result.ResultParameters | object | |
Result.ResultParameters.ResultParameter | array of object or object | One item or a list, depending on the API. |
Result.ResultParameters.ResultParameter[].Key | stringRequired | |
Result.ResultParameters.ResultParameter[].Value | string or number | |
Result.ReferenceData | object | |
Result.ReferenceData.ReferenceItem | array of object or object | |
Result.ReferenceData.ReferenceItem[].Key | stringRequired | |
Result.ReferenceData.ReferenceItem[].Value | string 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.
| Field | Type | Description |
|---|---|---|
Result | objectRequired | |
Result.ResultType | integerRequired | |
Result.ResultCode | integer or stringRequired | 0 means success. Some APIs send it as a string. |
Result.ResultDesc | stringRequired | |
Result.OriginatorConversationID | stringRequired | |
Result.ConversationID | stringRequired | |
Result.TransactionID | string | |
Result.ResultParameters | object | |
Result.ResultParameters.ResultParameter | array of object or object | One item or a list, depending on the API. |
Result.ResultParameters.ResultParameter[].Key | stringRequired | |
Result.ResultParameters.ResultParameter[].Value | string or number | |
Result.ReferenceData | object | |
Result.ReferenceData.ReferenceItem | array of object or object | |
Result.ReferenceData.ReferenceItem[].Key | stringRequired | |
Result.ReferenceData.ReferenceItem[].Value | string or number |