Refunds
Send money back to the M-Pesa number that paid a collection, in full or in part.
A refund is paid as a payout from your balance to the payer's number (payout metadata: refund_id, collection_id). Payout fees apply; the collection's own fee isn't returned.
Refunds on one collection never add up to more than it collected. Pending and succeeded refunds both count; a failed one frees its amount again.
Collections can be refunded for 180 days after payment. After that the payer's number is erased, so send a normal payout instead. Statuses: pending, succeeded, failed.
Send your API key as Authorization: Bearer apk_test_… (sandbox) or apk_live_… (live). Each endpoint lists the scope the key needs. See API keys.
Create a refund
/api/v1/refundsrefunds:write Idempotency-Key requiredRefund all or part of a paid collection. Leave out amount to refund everything not yet refunded.
collectionstringrequiredThe paid collection to refund (col_…).
amountintegeroptionalKES cents, whole shillings. Defaults to the amount not yet refunded.
reasonstringoptionalWhy you're refunding.
requested_by_customerduplicatefraudulentorder_cancelledotherreferencestringoptionalYour own id, up to 64 characters. Also the payout's reference.
metadataobjectoptionalUp to 20 string key-value pairs.
curl -X POST "https://api.autopayke.com/api/v1/refunds" \
-H "Authorization: Bearer $AUTOPAYKE_API_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{
"collection": "col_7Rm2Xq9Lt4Wz8Kb3Np6Vd1Hs",
"amount": 50000,
"reason": "order_cancelled",
"reference": "RMA-2041"
}'{
"ok": true,
"data": {
"id": "re_2Kd7Pw4Xn9Lt3Vb8Rq5Zm1Hc",
"object": "refund",
"livemode": false,
"status": "pending",
"amount": 50000,
"currency": "KES",
"collection": "col_7Rm2Xq9Lt4Wz8Kb3Np6Vd1Hs",
"payout": "po_8Fq2mZx7Lk3Rt9Vb",
"reason": "order_cancelled",
"reference": "RMA-2041",
"metadata": {},
"failure_code": null,
"failure_message": null,
"succeeded_at": null,
"created": "2026-11-03T09:10:00.000Z",
"updated": "2026-11-03T09:10:00.000Z"
}
}IDEMPOTENCY_KEY_REQUIREDIDEMPOTENCY_KEY_REUSEDNOT_FOUNDVALIDATION_ERRORREFUND_NOT_ALLOWEDREFUND_AMOUNT_EXCEEDEDINSUFFICIENT_BALANCECAPABILITY_PAUSEDPlus the key and rate errors any keyed call can return.
List refunds
/api/v1/refundsrefunds:readNewest first, in the key's environment.
limitintegeroptionalHow many to return, 1 to 100. Default 20.
starting_afterstringoptionalCursor for the next page: the id of the last item you got. Lists are newest first; when has_more is true, pass the last id here.
collectionstringoptionalOnly refunds of this collection.
statusstringoptionalOnly refunds in this status.
pendingsucceededfailed
curl "https://api.autopayke.com/api/v1/refunds" \
-H "Authorization: Bearer $AUTOPAYKE_API_KEY"{
"ok": true,
"data": {
"object": "list",
"data": [
{
"id": "re_2Kd7Pw4Xn9Lt3Vb8Rq5Zm1Hc",
"object": "refund",
"livemode": false,
"status": "pending",
"amount": 50000,
"currency": "KES",
"collection": "col_7Rm2Xq9Lt4Wz8Kb3Np6Vd1Hs",
"payout": "po_8Fq2mZx7Lk3Rt9Vb",
"reason": "order_cancelled",
"reference": "RMA-2041",
"metadata": {},
"failure_code": null,
"failure_message": null,
"succeeded_at": null,
"created": "2026-11-03T09:10:00.000Z",
"updated": "2026-11-03T09:10:00.000Z"
}
],
"has_more": false
}
}Get a refund
/api/v1/refunds/{id}refunds:readOne refund and where it stands.
idstringrequiredThe refund id (re_…).
curl "https://api.autopayke.com/api/v1/refunds/re_2Kd7Pw4Xn9Lt3Vb8Rq5Zm1Hc" \
-H "Authorization: Bearer $AUTOPAYKE_API_KEY"{
"ok": true,
"data": {
"id": "re_2Kd7Pw4Xn9Lt3Vb8Rq5Zm1Hc",
"object": "refund",
"livemode": false,
"status": "succeeded",
"amount": 50000,
"currency": "KES",
"collection": "col_7Rm2Xq9Lt4Wz8Kb3Np6Vd1Hs",
"payout": "po_8Fq2mZx7Lk3Rt9Vb",
"reason": "order_cancelled",
"reference": "RMA-2041",
"metadata": {},
"failure_code": null,
"failure_message": null,
"succeeded_at": "2026-11-03T09:10:00.000Z",
"created": "2026-11-03T09:10:00.000Z",
"updated": "2026-11-03T09:10:00.000Z"
}
}