Quickstart
From an API key to a confirmed M-PESA payment: mint a key, find your account id, send an STK Push, then get the result by webhook or by asking.
1. Mint an API key
In Dashboard → API keys, create a key with the scopes stk:initiate, transactions:read and accounts:read. It starts with mpk_ and is shown once: put it in your server's environment, never in a browser or an app.
2. Find your account id
Every payment names the paybill or till it goes to by its account id. Copy it from the account's page in the dashboard (Use in the API), or list your accounts:
# Paste your API key once (it starts with mpk_):
export MYPAYMENTS_KEY="mpk_your_key_here"
curl "https://api.mypayments.co.ke/api/v1/accounts" \
-H "Authorization: Bearer $MYPAYMENTS_KEY"Each item's uuid is the account id. More on accounts.
3. Send an STK Push
# Paste your API key once (it starts with mpk_):
export MYPAYMENTS_KEY="mpk_your_key_here"
curl -X POST https://api.mypayments.co.ke/api/v1/stk \
-H "Authorization: Bearer $MYPAYMENTS_KEY" \
-H "Content-Type: application/json" \
-d '{
"account": "5e2989df-905b-40e9-a056-8251c2e34a37",
"phone": "254712345678",
"amount": 100,
"reference": "INV-001",
"description": "WiFi 1hr",
"tracking_id": "order-8842"
}'The customer gets the M-PESA PIN prompt. The response tells you we asked Safaricom; it is not a payment yet:
{
"success": true,
"data": {
"transaction_uuid": "1d6aea1c-6911-455b-8300-2d347cc2a6e4",
"reference": "INV-001",
"status": "pending",
"customer_message": "Success. Request accepted for processing"
}
}reference is your key
reference must be unique in your business. Sending the same reference again returns the existing payment with already_exists: true and never prompts the customer twice, so retrying a timed-out request is safe. All STK fields.4. Get the result
By webhook (recommended)
Add an endpoint in Dashboard → Webhooks. When the payment settles we POST it to you, signed:
POST /your/endpoint HTTP/1.1
Content-Type: application/json
X-MyPayments-Event: payment.settled
X-MyPayments-Signature: t=1764784760,v1=5d41402abc4b2a76b9719d911017c592…
{
"event": "payment.settled",
"transaction": {
"uuid": "1d6aea1c-6911-455b-8300-2d347cc2a6e4",
"account_uuid": "5e2989df-905b-40e9-a056-8251c2e34a37",
"provider": "mpesa",
"direction": "collection",
"kind": "stk",
"amount": "100.00",
"reported_amount": "100.00",
"amount_mismatch": false,
"currency": "KES",
"phone": "254712345678",
"phone_sha256": "7132104d6aae9c3fac82095a42c2817952bca48e09d98d5bf4ac08218982fb90",
"reference": "INV-001",
"tracking_id": "order-8842",
"provider_receipt": "TL3BD2ZK1P",
"status": "settled",
"result_code": "0",
"result_desc": "The service request is processed successfully.",
"verified": true,
"settled_at": "2026-12-03T17:59:20.102059Z",
"created_at": "2026-12-03T17:59:11.806152Z",
"source": "provider"
}
}Verify the signature, fulfil the order once per reference, and answer 2xx. Or send this one payment somewhere else by adding callback_url to the STK request.
By asking
# Paste your API key once (it starts with mpk_):
export MYPAYMENTS_KEY="mpk_your_key_here"
curl "https://api.mypayments.co.ke/api/v1/transactions/INV-001" \
-H "Authorization: Bearer $MYPAYMENTS_KEY"Pass your reference or the transaction_uuid. status becomes settled (paid and confirmed with Safaricom) or failed. To find payments by your own tracking_id, list with ?tracking_id=. Transactions.
Next
- Customers paying your paybill directly: C2B and account numbers.
- Route payments to several systems: webhooks.
- Try it with test money first: testing in the sandbox.