daraja-openapi

API reference / C2B

Register C2B confirmation and validation URLs

POST/mpesa/c2b/v2/registerurl

Checked against the Safaricom sandbox on 1 December 2026

Tells M-PESA where to send customer payments made to your paybill or till from the M-PESA menu or app. Validation is off unless Safaricom enables it for your shortcode; ResponseType decides what happens if your validation URL does not answer. In production a shortcode's URLs can be registered once; changing them needs Safaricom's help. Daraja refuses URLs that contain words such as mpesa, safaricom, exec, cmd or sql, so keep them out of your paths. Daraja spells the response field OriginatorCoversationID, without the second "n".

In the SDKs

SDKMethod
TypeScriptc2bRegisterUrls()
Pythonc2b_register_urls()
PHPc2bRegisterUrls()
Kotlinc2bRegisterUrls()
Swiftc2bRegisterURLs()

Request

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

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

FieldTypeDescription
ShortCodestringRequiredA paybill or till number. Matches ^[0-9]{5,7}$.
ResponseTypestringRequiredWhat M-PESA does when your validation URL doesn't answer in time. One of Completed, Cancelled.
ConfirmationURLstring (uri)RequiredMatches ^https://.
ValidationURLstring (uri)RequiredMatches ^https://.

Example request

curl -X POST "https://sandbox.safaricom.co.ke/mpesa/c2b/v2/registerurl" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "ShortCode": "600984",
  "ResponseType": "Completed",
  "ConfirmationURL": "https://example.com/payments/c2b/confirmation",
  "ValidationURL": "https://example.com/payments/c2b/validation"
}'

Response

The URLs were registered.

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": "7619-37765134-1",
  "ResponseCode": "0",
  "ResponseDescription": "success"
}

Callbacks

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

Accept or reject an incoming payment

Sent to ValidationURL from your request.

Sent before M-PESA completes the payment, only if validation is enabled for your shortcode. Answer within a few seconds; ResultCode "0" accepts.

FieldTypeDescription
TransactionTypestringRequired
TransIDstringRequiredThe M-PESA receipt.
TransTimestringRequiredThe time of the request in Kenyan time (EAT), formatted YYYYMMDDHHmmss. Matches ^[0-9]{14}$.
TransAmountstringRequiredAmount as a decimal string, e.g. "250.00".
BusinessShortCodestringRequired
BillRefNumberstring
InvoiceNumberstring
OrgAccountBalancestring
ThirdPartyTransIDstring
MSISDNstringThe payer's number. Recent Daraja versions mask or hash it.
FirstNamestring
MiddleNamestring
LastNamestring

Your answer:

FieldTypeDescription
ResultCodestringRequired"0" accepts. Rejection codes include C2B00011 (invalid MSISDN), C2B00012 (invalid account number), C2B00013 (invalid amount) and C2B00016 (other).
ResultDescstringRequired

Example answer

{
  "ResultCode": "0",
  "ResultDesc": "Accepted"
}

A completed customer payment

Sent to ConfirmationURL from your request.

Sent after the customer has paid. The payment has already happened, so record it and answer HTTP 200. Like other Daraja callbacks it is not signed; confirm large amounts with the Transaction Status query.

FieldTypeDescription
TransactionTypestringRequired
TransIDstringRequiredThe M-PESA receipt.
TransTimestringRequiredThe time of the request in Kenyan time (EAT), formatted YYYYMMDDHHmmss. Matches ^[0-9]{14}$.
TransAmountstringRequiredAmount as a decimal string, e.g. "250.00".
BusinessShortCodestringRequired
BillRefNumberstring
InvoiceNumberstring
OrgAccountBalancestring
ThirdPartyTransIDstring
MSISDNstringThe payer's number. Recent Daraja versions mask or hash it.
FirstNamestring
MiddleNamestring
LastNamestring

Example body

{
  "TransactionType": "Pay Bill",
  "TransID": "TKU3XXXXXX",
  "TransTime": "20261201101500",
  "TransAmount": "250.00",
  "BusinessShortCode": "600984",
  "BillRefNumber": "INV-1001",
  "InvoiceNumber": "",
  "OrgAccountBalance": "49197.00",
  "ThirdPartyTransID": "",
  "MSISDN": "2547 ***** 149",
  "FirstName": "JOHN"
}

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.