Payments — Africa
What is the Daraja API? Safaricom M-Pesa Integration Guide
The Daraja API is Safaricom’s gateway to M-Pesa — learn STK Push, B2C, C2B, auth, callbacks and how Kenyan businesses integrate payments in 2026.
If you have ever paid for goods through Lipa Na M-Pesa, received a salary into your phone, or topped up your Netflix subscription with mobile money, you have used a service powered by the Daraja API. Daraja is Safaricom’s official public API for M-Pesa — the gateway that lets developers and businesses move money in and out of the largest mobile money network in the world. In this guide we explain exactly what the Daraja API is, what each of its endpoints does, how to integrate it, and the practical pitfalls that catch most teams the first time.
M-Pesa processes more than US$314 billion in transaction value annually across East Africa (Safaricom FY 2024 results), and Daraja is how every modern Kenyan e-commerce site, SaaS platform, fintech and SME plugs into that flow. Whether you are a developer building a new payment journey or a founder evaluating the work involved, this article has you covered.
The Daraja API is a RESTful HTTPS interface published by Safaricom that exposes M-Pesa functionality to third-party applications. The name “Daraja” is Swahili for “bridge” — the API bridges your application to Safaricom’s core M-Pesa infrastructure. Through Daraja you can:
Daraja replaced the older G2 SOAP API in 2017 and has become the standard way to integrate with M-Pesa Kenya. Sister Daraja portals now also serve M-Pesa in Tanzania, Mozambique, DRC and Ghana, although each has its own credentials.
Daraja uses OAuth 2.0 client-credentials. Every request must include a Bearer token, which you obtain by exchanging your Consumer Key and Consumer Secret at:
GET https://api.safaricom.co.ke/oauth/v1/generate?grant_type=client_credentials
Authorization: Basic base64(consumerKey:consumerSecret)The response gives you an access_token valid for 3,600 seconds (1 hour). Cache it server-side; do not regenerate on every call. Use https://sandbox.safaricom.co.ke for testing and the production host once approved.
STK Push (also called Lipa Na M-Pesa Online) is the most common integration. You send a request, and Safaricom triggers a payment prompt directly on the customer’s phone. They enter their PIN, and the funds move to your PayBill or Till.
POST https://api.safaricom.co.ke/mpesa/stkpush/v1/processrequest
Authorization: Bearer <access_token>
Content-Type: application/json
{
"BusinessShortCode": 174379,
"Password": "<base64(shortcode+passkey+timestamp)>",
"Timestamp": "20260615120000",
"TransactionType": "CustomerPayBillOnline",
"Amount": 1500,
"PartyA": 254712345678,
"PartyB": 174379,
"PhoneNumber": 254712345678,
"CallBackURL": "https://yourapp.com/mpesa/callback",
"AccountReference": "INV-1042",
"TransactionDesc": "Payment for invoice 1042"
}The customer prompt arrives within 5–10 seconds. They have 60 seconds to enter their PIN. Daraja then POSTs the result to your CallBackURL within another 10–30 seconds, with a ResultCode of 0 for success or a non-zero error code.
C2B lets customers pay your PayBill or Till independently — from the M-Pesa menu, not triggered by your app. You register validation and confirmation URLs once, and Daraja calls them every time a customer sends money to your shortcode. Use this for paying invoices, school fees, or topping up wallets.
B2C is for payouts: salaries, supplier payments, betting winnings, insurance claims. You initiate the payment from your application, Safaricom moves the funds, and you receive a callback with the result. Requires a separate Business Shortcode and initiator credentials.
Used to confirm the state of a transaction (settled, pending, reversed). Critical when a callback was missed due to a server outage — do not rely on callbacks alone; reconcile with Transaction Status nightly.
Returns the live balance of your PayBill or Till. Useful for paying out from a float without going negative.
CheckoutRequestID + MpesaReceiptNumber.End-to-end go-live typically takes 2–6 weeks depending on Safaricom’s queue and how clean your paperwork is.
Password field is base64 of (Shortcode + Passkey + Timestamp). Many failed integrations boil down to encoding bugs here.YYYYMMDDHHMMSS in Africa/Nairobi time. UTC drift causes silent rejections.You don’t have to integrate Daraja yourself. If you sell on Shopify, WooCommerce, or run a SaaS that needs M-Pesa, there are gateway providers (Pesapal, Flutterwave, IntaSend, HelloDuty) that wrap Daraja behind a simpler API or a no-code dashboard. They handle the shortcode application, token refresh, callbacks and reconciliation — you get a checkout button or a single REST endpoint.
At HelloDuty we connect M-Pesa to the rest of the customer-engagement stack: when a customer pays an invoice, we can automatically send an SMS receipt and trigger a WhatsApp follow-up — see how to send bulk SMS in Kenya effectively and WhatsApp integration for better customer experience. We also cover the broader picture in the comprehensive guide to building USSD applications for feature-phone payments.
Yes, the API itself is free. You pay Safaricom’s normal M-Pesa transaction fees — settlement is governed by your PayBill or Till tariff, not by per-API-call charges.
STK Push is initiated by your application — Safaricom prompts the customer to pay. C2B is initiated by the customer from the M-Pesa menu — your application reacts to a confirmation callback. Most checkout journeys use STK Push for the lower friction.
Typically 2–6 weeks from clean paperwork to live access, including Safaricom’s integration testing. Companies in regulated sectors (banking, insurance, betting) take longer.
Yes — use a gateway like Pesapal, IntaSend, Flutterwave or HelloDuty. They publish drop-in checkout buttons and webhooks, abstracting away token refresh, callbacks and reconciliation.
Safaricom’s Daraja is Kenya-only. M-Pesa Tanzania, Mozambique, DRC and Ghana run their own developer portals with similar but separate APIs. If you operate across markets, choose a provider that wraps all of them behind a single API.
The Daraja API is the bridge between your application and the largest mobile money network in Africa. With around an hour of focused engineering you can run sandbox STK Push end-to-end; with a few more weeks you can be live in production with a production PayBill. If you want the result without the boilerplate, HelloDuty packages M-Pesa, SMS, WhatsApp Business and AI voice into a single platform that your team can run from a dashboard.
Talk to us if you want to take M-Pesa payments alongside your customer-engagement channels — we will scope your integration in a 20-minute call.

Are you ready to get started? Sign up here for a demo of the HelloDuty CRM and customer engagement automation software now.

Plan, engage, and analyse with ease. Transform your customer relationship with an all-in-one platform.
