Skip to content

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

POST/api/v1/collections
API keycollections:write Idempotency-Key required

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

Body (JSON)
  • amountintegerrequired

    What the customer pays, in KES cents, whole shillings only. KES 10 (1000) to KES 150,000 (15000000).

  • currencystringoptional

    Always "KES".

    KES
  • payerobjectrequired

    { phone, name? }. phone: a Safaricom M-Pesa number in any common format (+254712345678, 0712345678). name: the customer's name, for your records and receipts.

  • referencestringoptional

    Your own id, up to 64 characters (an order or invoice). Searchable; not unique.

  • descriptionstringoptional

    Up to 140 characters.

  • metadataobjectoptional

    Up to 20 string key-value pairs, returned on the collection, its events and webhooks.

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

    col_ followed by 24 characters.

  • statusstring

    pending, succeeded, failed or expired.

    pendingsucceededfailedexpired
  • amountinteger

    What the customer was asked to pay, in KES cents.

  • methodstring

    How they pay. Always "mpesa_prompt" for now.

  • payerobject

    { phone, name }: the number prompted (masked) and the name you sent.

  • credited_usdcstring | null

    USDC that reached your balance, once succeeded.

  • fee_usdcstring | null

    The collection fee taken before crediting, once succeeded.

  • ratestring | null

    KES per USDC used to convert the payment.

  • mpesa_receiptstring | null

    The customer's M-Pesa receipt code, once succeeded. Test receipts start with TEST.

  • failure_codestring | null

    PAYER_CANCELLED, INSUFFICIENT_FUNDS or PROMPT_EXPIRED when it didn't succeed.

  • expires_atstring

    When an unanswered prompt expires (10 minutes after creation).

  • paid_atstring | null

    When the customer paid.

  • 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

GET/api/v1/collections
API keycollections:read

Your collections, newest first, in the key's environment. Filter by status, your reference or a time window.

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.

  • statusstringoptional

    Only collections in this status.

    pendingsucceededfailedexpired
  • referencestringoptional

    Only collections with this reference.

  • created_gtestringoptional

    Created at or after this ISO 8601 time.

  • created_ltstringoptional

    Created before this ISO 8601 time.

Request
curl "https://api.autopayke.com/api/v1/collections?limit=20&status=succeeded" \
  -H "Authorization: Bearer $AUTOPAYKE_API_KEY"
Response200 application/json
{
  "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

GET/api/v1/collections/{id}
API keycollections:read

One collection by id, with its current status and how much of it has been refunded. Use it to recover after a missed webhook.

Path parameters
  • idstringrequired

    The collection id (col_…).

Request
curl "https://api.autopayke.com/api/v1/collections/col_5Ty8nQw3Rz2Lm7Kc9Pd4Hs1V" \
  -H "Authorization: Bearer $AUTOPAYKE_API_KEY"
Response200 application/json
{
  "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
  }
}
Response fields
  • idstring

    col_ followed by 24 characters.

  • statusstring

    pending, succeeded, failed or expired.

    pendingsucceededfailedexpired
  • amountinteger

    What the customer was asked to pay, in KES cents.

  • methodstring

    How they pay. Always "mpesa_prompt" for now.

  • payerobject

    { phone, name }: the number prompted (masked) and the name you sent.

  • credited_usdcstring | null

    USDC that reached your balance, once succeeded.

  • fee_usdcstring | null

    The collection fee taken before crediting, once succeeded.

  • ratestring | null

    KES per USDC used to convert the payment.

  • mpesa_receiptstring | null

    The customer's M-Pesa receipt code, once succeeded. Test receipts start with TEST.

  • failure_codestring | null

    PAYER_CANCELLED, INSUFFICIENT_FUNDS or PROMPT_EXPIRED when it didn't succeed.

  • expires_atstring

    When an unanswered prompt expires (10 minutes after creation).

  • paid_atstring | null

    When the customer paid.

  • amount_refundedinteger

    KES cents refunded or being refunded (only on this endpoint).

Errors

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