Collections
Charge a customer by M-Pesa. Their phone rings with a prompt; once they pay, the money lands in your balance as USDC.
A collection moves from pending to succeeded, failed (cancelled, wrong PIN, not enough money) or expired (not answered within 10 minutes). It never goes backwards.
Every create needs an Idempotency-Key header, so a retry after a timeout can never ring the customer twice. Ship goods only on collection.succeeded.
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 collection
/api/v1/collectionscollections:write Idempotency-Key requiredRing a customer's phone with an M-Pesa prompt for the amount. It returns at once with status pending; the result arrives by webhook, usually within a minute.
amountintegerrequiredWhat the customer pays, in KES cents, whole shillings only. KES 10 (1000) to KES 150,000 (15000000).
currencystringoptionalAlways "KES".
KESpayerobjectrequired{ phone, name? }. phone: a Safaricom M-Pesa number in any common format (+254712345678, 0712345678). name: the customer's name, for your records and receipts.
referencestringoptionalYour own id, up to 64 characters (an order or invoice). Searchable; not unique.
descriptionstringoptionalUp to 140 characters.
metadataobjectoptionalUp to 20 string key-value pairs, returned on the collection, its events and webhooks.
curl -X POST "https://api.autopayke.com/api/v1/collections" \
-H "Authorization: Bearer $AUTOPAYKE_API_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{
"amount": 150000,
"currency": "KES",
"payer": {
"phone": "+254700000001",
"name": "Jane Wanjiku"
},
"reference": "order_1042",
"description": "Order 1042",
"metadata": {
"cart_id": "c_7781"
}
}'{
"ok": true,
"data": {
"id": "col_5Ty8nQw3Rz2Lm7Kc9Pd4Hs1V",
"object": "collection",
"livemode": false,
"status": "pending",
"amount": 150000,
"currency": "KES",
"method": "mpesa_prompt",
"payer": {
"phone": "+2547•••••001",
"name": "Jane Wanjiku"
},
"credited_usdc": null,
"fee_usdc": null,
"rate": null,
"mpesa_receipt": null,
"reference": "order_1042",
"description": "Order 1042",
"metadata": {
"cart_id": "c_7781"
},
"failure_code": null,
"failure_message": null,
"expires_at": "2026-11-03T09:20:00.000Z",
"paid_at": null,
"created": "2026-11-03T09:10:00.000Z",
"updated": "2026-11-03T09:10:00.000Z"
}
}idstringcol_ followed by 24 characters.
statusstringpending, succeeded, failed or expired.
pendingsucceededfailedexpiredamountintegerWhat the customer was asked to pay, in KES cents.
methodstringHow they pay. Always "mpesa_prompt" for now.
payerobject{ phone, name }: the number prompted (masked) and the name you sent.
credited_usdcstring | nullUSDC that reached your balance, once succeeded.
fee_usdcstring | nullThe collection fee taken before crediting, once succeeded.
ratestring | nullKES per USDC used to convert the payment.
mpesa_receiptstring | nullThe customer's M-Pesa receipt code, once succeeded. Test receipts start with TEST.
failure_codestring | nullPAYER_CANCELLED, INSUFFICIENT_FUNDS or PROMPT_EXPIRED when it didn't succeed.
expires_atstringWhen an unanswered prompt expires (10 minutes after creation).
paid_atstring | nullWhen the customer paid.
IDEMPOTENCY_KEY_REQUIREDIDEMPOTENCY_KEY_REUSEDVALIDATION_ERRORPAYER_INVALIDPAYER_PROMPT_LIMITLIMIT_PER_COLLECTION_EXCEEDEDLIMIT_DAILY_EXCEEDEDLIMIT_MONTHLY_EXCEEDEDMETHOD_UNAVAILABLECAPABILITY_PAUSEDPlus the key and rate errors any keyed call can return.
- One phone can get at most 3 prompts in 10 minutes and 10 a day, across every business on AutoPayKe, so a leaked key can't be used to spam people.
- Sandbox: +254700000001 succeeds, +254700000002 is cancelled, +254700000003 fails for insufficient funds, +254700000004 expires. Anything else succeeds about 5 seconds later, and a success adds credited_usdc to your sandbox balance.
List collections
/api/v1/collectionscollections:readYour collections, newest first, in the key's environment. Filter by status, your reference or a time window.
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.
statusstringoptionalOnly collections in this status.
pendingsucceededfailedexpiredreferencestringoptionalOnly collections with this reference.
created_gtestringoptionalCreated at or after this ISO 8601 time.
created_ltstringoptionalCreated before this ISO 8601 time.
curl "https://api.autopayke.com/api/v1/collections?limit=20&status=succeeded" \
-H "Authorization: Bearer $AUTOPAYKE_API_KEY"{
"ok": true,
"data": {
"object": "list",
"data": [
{
"id": "col_5Ty8nQw3Rz2Lm7Kc9Pd4Hs1V",
"object": "collection",
"livemode": false,
"status": "succeeded",
"amount": 150000,
"currency": "KES",
"method": "mpesa_prompt",
"payer": {
"phone": "+2547•••••001",
"name": "Jane Wanjiku"
},
"credited_usdc": "11.530000",
"fee_usdc": "0.116000",
"rate": "128.80",
"mpesa_receipt": "TKA4Q7LM2X",
"reference": "order_1042",
"description": "Order 1042",
"metadata": {
"cart_id": "c_7781"
},
"failure_code": null,
"failure_message": null,
"expires_at": "2026-11-03T09:20:00.000Z",
"paid_at": "2026-11-03T09:10:41.000Z",
"created": "2026-11-03T09:10:00.000Z",
"updated": "2026-11-03T09:10:41.000Z"
}
],
"has_more": false
}
}Get a collection
/api/v1/collections/{id}collections:readOne collection by id, with its current status and how much of it has been refunded. Use it to recover after a missed webhook.
idstringrequiredThe collection id (col_…).
curl "https://api.autopayke.com/api/v1/collections/col_5Ty8nQw3Rz2Lm7Kc9Pd4Hs1V" \
-H "Authorization: Bearer $AUTOPAYKE_API_KEY"{
"ok": true,
"data": {
"id": "col_5Ty8nQw3Rz2Lm7Kc9Pd4Hs1V",
"object": "collection",
"livemode": false,
"status": "succeeded",
"amount": 150000,
"currency": "KES",
"method": "mpesa_prompt",
"payer": {
"phone": "+2547•••••001",
"name": "Jane Wanjiku"
},
"credited_usdc": "11.530000",
"fee_usdc": "0.116000",
"rate": "128.80",
"mpesa_receipt": "TKA4Q7LM2X",
"reference": "order_1042",
"description": "Order 1042",
"metadata": {
"cart_id": "c_7781"
},
"failure_code": null,
"failure_message": null,
"expires_at": "2026-11-03T09:20:00.000Z",
"paid_at": "2026-11-03T09:10:41.000Z",
"created": "2026-11-03T09:10:00.000Z",
"updated": "2026-11-03T09:10:41.000Z",
"amount_refunded": 0
}
}idstringcol_ followed by 24 characters.
statusstringpending, succeeded, failed or expired.
pendingsucceededfailedexpiredamountintegerWhat the customer was asked to pay, in KES cents.
methodstringHow they pay. Always "mpesa_prompt" for now.
payerobject{ phone, name }: the number prompted (masked) and the name you sent.
credited_usdcstring | nullUSDC that reached your balance, once succeeded.
fee_usdcstring | nullThe collection fee taken before crediting, once succeeded.
ratestring | nullKES per USDC used to convert the payment.
mpesa_receiptstring | nullThe customer's M-Pesa receipt code, once succeeded. Test receipts start with TEST.
failure_codestring | nullPAYER_CANCELLED, INSUFFICIENT_FUNDS or PROMPT_EXPIRED when it didn't succeed.
expires_atstringWhen an unanswered prompt expires (10 minutes after creation).
paid_atstring | nullWhen the customer paid.
amount_refundedintegerKES cents refunded or being refunded (only on this endpoint).