Skip to content

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

POST/api/v1/refunds
API keyrefunds:write Idempotency-Key required

Refund all or part of a paid collection. Leave out amount to refund everything not yet refunded.

Body (JSON)
  • collectionstringrequired

    The paid collection to refund (col_…).

  • amountintegeroptional

    KES cents, whole shillings. Defaults to the amount not yet refunded.

  • reasonstringoptional

    Why you're refunding.

    requested_by_customerduplicatefraudulentorder_cancelledother
  • referencestringoptional

    Your own id, up to 64 characters. Also the payout's reference.

  • metadataobjectoptional

    Up to 20 string key-value pairs.

Request
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"
  }'
Response201 application/json
{
  "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"
  }
}

List refunds

GET/api/v1/refunds
API keyrefunds:read

Newest first, in the key's environment.

Query parameters
  • limitintegeroptional

    How many to return, 1 to 100. Default 20.

  • starting_afterstringoptional

    Cursor 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.

  • collectionstringoptional

    Only refunds of this collection.

  • statusstringoptional

    Only refunds in this status.

    pendingsucceededfailed
Request
curl "https://api.autopayke.com/api/v1/refunds" \
  -H "Authorization: Bearer $AUTOPAYKE_API_KEY"
Response200 application/json
{
  "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

GET/api/v1/refunds/{id}
API keyrefunds:read

One refund and where it stands.

Path parameters
  • idstringrequired

    The refund id (re_…).

Request
curl "https://api.autopayke.com/api/v1/refunds/re_2Kd7Pw4Xn9Lt3Vb8Rq5Zm1Hc" \
  -H "Authorization: Bearer $AUTOPAYKE_API_KEY"
Response200 application/json
{
  "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"
  }
}
Errors

Plus the key and rate errors any keyed call can return.