daraja-openapi

API reference / C2B

Simulate a customer payment (sandbox only)

POST/mpesa/c2b/v2/simulate

Checked against the Safaricom sandbox on 1 December 2026. Sandbox only: not available in production

Makes the sandbox send your confirmation (and validation) callbacks as if a customer had paid. Not available in production.

In the SDKs

SDKMethod
TypeScriptc2bSimulate()
Pythonc2b_simulate()
PHPc2bSimulate()
Kotlinc2bSimulate()
SwiftThrough the generated client: daraja.raw.c2bSimulate()

Request

EnvironmentURL
Sandboxhttps://sandbox.safaricom.co.ke/mpesa/c2b/v2/simulate
Productionhttps://api.safaricom.co.ke/mpesa/c2b/v2/simulate

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

FieldTypeDescription
ShortCodestringRequiredA paybill or till number. Matches ^[0-9]{5,7}$.
CommandIDstringRequiredOne of CustomerPayBillOnline, CustomerBuyGoodsOnline.
AmountintegerRequiredAt least 1.
MsisdnstringRequiredA Kenyan mobile number in international format without the plus, e.g. 254708374149. Matches ^254(7|1)[0-9]{8}$.
BillRefNumberstringThe account number. Leave out for a till.

Example request

curl -X POST "https://sandbox.safaricom.co.ke/mpesa/c2b/v2/simulate" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "ShortCode": "600984",
  "CommandID": "CustomerPayBillOnline",
  "Amount": 250,
  "Msisdn": "254708374149",
  "BillRefNumber": "INV-1001"
}'

Response

The simulated payment was accepted.

FieldTypeDescription
OriginatorCoversationIDstringSpelled this way by Daraja.
ResponseCodestringRequired
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

{
  "OriginatorCoversationID": "53e3-4aa8-9fe0-8fb5e4092cdd3405976",
  "ResponseCode": "0",
  "ResponseDescription": "Accept the service request successfully."
}

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.