daraja-openapi

API reference / Reversal

Reverse a customer payment

POST/mpesa/reversal/v1/request

Checked against the Safaricom sandbox on 1 December 2026

Asks M-PESA to reverse a payment your shortcode received, identified by its receipt (TransactionID). Only the full amount can be reversed. The result arrives at ResultURL.

In the SDKs

SDKMethod
TypeScriptreversal()
Pythonreversal()
PHPreversal()
Kotlinreversal()
SwiftThrough the generated client: daraja.raw.reversal()

Request

EnvironmentURL
Sandboxhttps://sandbox.safaricom.co.ke/mpesa/reversal/v1/request
Productionhttps://api.safaricom.co.ke/mpesa/reversal/v1/request

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 TransactionReversal.
TransactionIDstringRequiredThe M-PESA receipt of the payment to reverse.
AmountintegerRequiredAt least 1.
ReceiverPartystringRequiredA paybill or till number. Matches ^[0-9]{5,7}$.
RecieverIdentifierTypestringRequired"11" for a reversal. Spelled this way by Daraja. Always 11.
ResultURLstring (uri)RequiredMatches ^https://.
QueueTimeOutURLstring (uri)RequiredMatches ^https://.
RemarksstringRequired2–100 characters.
Occasionstring

Example request

curl -X POST "https://sandbox.safaricom.co.ke/mpesa/reversal/v1/request" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "Initiator": "testapi",
  "SecurityCredential": "EsJocK7+NjqZPC3I3EO+TbvS+xVb9TymWwaKABoaZr/Z/n0UysSs..",
  "CommandID": "TransactionReversal",
  "TransactionID": "TKU3XXXXXX",
  "Amount": 250,
  "ReceiverParty": "600984",
  "RecieverIdentifierType": "11",
  "ResultURL": "https://example.com/mpesa/reversal/result",
  "QueueTimeOutURL": "https://example.com/mpesa/reversal/timeout",
  "Remarks": "Paid twice"
}'

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.