API reference / C2B
Register C2B confirmation and validation URLs
/mpesa/c2b/v2/registerurlChecked 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
| SDK | Method |
|---|---|
| TypeScript | c2bRegisterUrls() |
| Python | c2b_register_urls() |
| PHP | c2bRegisterUrls() |
| Kotlin | c2bRegisterUrls() |
| Swift | c2bRegisterURLs() |
Request
| Environment | URL |
|---|---|
| Sandbox | https://sandbox.safaricom.co.ke/mpesa/c2b/v2/registerurl |
| Production | https://api.safaricom.co.ke/mpesa/c2b/v2/registerurl |
Send the access token as Authorization: Bearer <token>, and the body as JSON.
| Field | Type | Description |
|---|---|---|
ShortCode | stringRequired | A paybill or till number. Matches ^[0-9]{5,7}$. |
ResponseType | stringRequired | What M-PESA does when your validation URL doesn't answer in time. One of Completed, Cancelled. |
ConfirmationURL | string (uri)Required | Matches ^https://. |
ValidationURL | string (uri)Required | Matches ^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.
| Field | Type | Description |
|---|---|---|
OriginatorCoversationID | string | Spelled this way by Daraja. |
ResponseCode | stringRequired | |
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
{
"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.
| Field | Type | Description |
|---|---|---|
TransactionType | stringRequired | |
TransID | stringRequired | The M-PESA receipt. |
TransTime | stringRequired | The time of the request in Kenyan time (EAT), formatted YYYYMMDDHHmmss. Matches ^[0-9]{14}$. |
TransAmount | stringRequired | Amount as a decimal string, e.g. "250.00". |
BusinessShortCode | stringRequired | |
BillRefNumber | string | |
InvoiceNumber | string | |
OrgAccountBalance | string | |
ThirdPartyTransID | string | |
MSISDN | string | The payer's number. Recent Daraja versions mask or hash it. |
FirstName | string | |
MiddleName | string | |
LastName | string |
Your answer:
| Field | Type | Description |
|---|---|---|
ResultCode | stringRequired | "0" accepts. Rejection codes include C2B00011 (invalid MSISDN), C2B00012 (invalid account number), C2B00013 (invalid amount) and C2B00016 (other). |
ResultDesc | stringRequired |
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.
| Field | Type | Description |
|---|---|---|
TransactionType | stringRequired | |
TransID | stringRequired | The M-PESA receipt. |
TransTime | stringRequired | The time of the request in Kenyan time (EAT), formatted YYYYMMDDHHmmss. Matches ^[0-9]{14}$. |
TransAmount | stringRequired | Amount as a decimal string, e.g. "250.00". |
BusinessShortCode | stringRequired | |
BillRefNumber | string | |
InvoiceNumber | string | |
OrgAccountBalance | string | |
ThirdPartyTransID | string | |
MSISDN | string | The payer's number. Recent Daraja versions mask or hash it. |
FirstName | string | |
MiddleName | string | |
LastName | string |
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"
}