1
Create an API key
Sign in to your Fortpesa dashboard and open Settings → API keys. Create a key —
it is shown once, so copy it immediately.
Keys are tied to your merchant account. Never embed keys in client-side code — call the
Fortpesa API from your server.
2
Initiate an STK Push
Prompt the customer’s phone for a payment. This example charges KES 150 (You get
15000
minor units):Your merchant account needs an approved payment channel (request one under
Channels in the dashboard) and prepaid wallet balance for platform fees —
otherwise the request fails with
503 or 402 INSUFFICIENT_CREDIT.201 Created with a transaction whose status is pending — the customer now
sees an M-Pesa prompt on their phone.3
Wait for the result
A payment reaches a final (terminal) state within a couple of minutes. Get notified in
one of two ways:
-
Webhooks (recommended) — we POST a signed
transaction.success/transaction.failedevent to your endpoint. See Webhooks. -
Polling — repeatedly read the transaction until its status is terminal:
Next steps
- Authentication — keys, headers, rate limits
- Create STK Push — full request and error reference
- Webhooks — verify signatures and handle events