BluePayAPI
Ask AI
BluePay
API Keys Support Dashboard

Collect a payment

Your server starts an M-Pesa prompt. Store the ids you get back.

Collect a payment

Your server calls STK push. Safaricom shows the prompt on the customer’s phone. You then confirm the result.

Request

FieldRequiredUse
api_secret, account_id, channel_idYesFrom API Keys. See Authentication.
phoneYesKenya number, 2547…. Alias phone_number.
amountYesKES 1–250000.
account_referenceNoYour invoice id, max 64 characters. Send the same value as external_reference if you prefer that name. Omit it and BluePay generates one.
callback_urlNoWebhook for this STK only. Otherwise BluePay uses the Account callback URL.

What to store

Save these from the STK response before you show “waiting for M-Pesa” in your app:

  • checkout_request_id — best key for payment status.
  • stk_request_id — BluePay’s integer id for that push.
  • account_reference — the invoice id, yours or the one BluePay generated. Status returns the newest STK for that id.
Prepaid accounts need enough service tokens before the push. A 402 with error_code INSUFFICIENT_PREPAID includes required_kes and balance_kes. Top up, then retry. Postpaid accounts skip that check. The fee is debited when the payment succeeds.

Samples, error codes, and the full body are on STK push.