On this page
Daraja is Safaricom's API platform: the official door through which websites, apps and business systems connect to M-Pesa. With the Daraja API explained in one line, it lets your software send payment prompts, hear about payments as they arrive, and send money out, without anyone typing into the M-Pesa menu. Your developer writes the code. You, as the owner, hold the keys, approve go-live and decide who has access. This guide covers that owner's half, which developer tutorials skip.
What Daraja is
Before Daraja, connecting to M-Pesa meant long agreements and bespoke technical setups that only large firms bothered with. Daraja opened the same services to any registered business with a shortcode, through a self-service portal at developer.safaricom.co.ke with published documentation.
An API (application programming interface) is simply a set of agreed messages. Your system sends Safaricom a message in an agreed format ("ask 0712… to pay KES 2,500 for order 381"), and Safaricom answers in an agreed format. Nothing about it is visible to customers except the result: a prompt on their phone, or money arriving in their wallet.
Three accounts are involved, and owners often confuse them:
- Your shortcode: the Till or Paybill itself, where money lands.
- The M-Pesa organisation portal: the web portal for that shortcode, used for statements, user roles and approvals.
- The Daraja developer account: where apps are created and credentials issued.
APIs that matter: STK push, C2B, B2C and status
Daraja lists many services. Most businesses only ever use four or five of them.
| Service | Direction | Used for |
|---|---|---|
| M-Pesa Express (STK push) | Customer pays you, prompted by your system | Website and app checkouts, deposits, invoice "pay now" buttons |
| C2B (customer to business) | Customer pays you from the M-Pesa menu | Getting instant notice of manual Paybill or Till payments so they post automatically |
| B2C (business to customer) | You pay customers | Refunds, loan disbursements, salaries, winnings, agent commissions |
| Transaction status | Query | Checking the outcome of a payment your system missed |
| Account balance and reversal | Query / correction | Balance checks; reversing payments sent in error |
For a typical shop or service website, STK push plus C2B covers almost everything. Our explainer on how STK push works on a website walks through that flow in detail. B2C matters for lenders, SACCOs, betting and payout businesses, and it carries more risk, because it moves money out. Safaricom applies extra checks before approving it, and you should apply extra controls inside your own system.
Safaricom adds and updates services over time, including billing and standing-order tools, so ask your developer to check the current product list rather than assuming.
Sandbox vs production
Daraja has two worlds:
- Sandbox: test credentials, a test shortcode, test phone numbers. No real money. Developers build and break things here.
- Production: your real shortcode, real customers, real money. Credentials are different and issued only after go-live.
A working sandbox demo proves the code is roughly right. It does not prove your live shortcode is configured correctly, that your callback URL is reachable from Safaricom's production servers, or that the business name on the prompt is what customers expect. Expect a short round of fixes after go-live, and do not announce the new checkout until it has handled real payments.
Going live: what the owner must do
This is where projects stall, usually for administrative rather than technical reasons. The go-live process on the Daraja portal links your developer's app to your real shortcode, and it needs someone with authority over that shortcode.
The owner's checklist
- Confirm the shortcode is registered to the business and active.
- Find out who holds the organisation portal administrator role. If it is a former employee or a phone number nobody has, sort that out with Safaricom first. This alone can take weeks.
- Create the Daraja account under a business email you control, such as payments@yourcompany.co.ke, not the developer's personal Gmail.
- Be available during go-live. The process verifies the shortcode using a one-time code sent to the administrator. If that person is travelling to Kisumu with no network, nothing moves.
- Receive the production credentials yourself, including the Lipa Na M-Pesa passkey for STK push, then pass them to your developer through a secure channel.
- Approve the callback URLs your developer registers, so you know where payment data is being sent.
Your developer's job is the code, the hosting, the HTTPS certificate, the test plan and fixing what the first live payments reveal. Splitting it like this keeps ownership where it belongs.
Keeping API credentials safe
Your consumer key, consumer secret and passkey let software act on your shortcode. For B2C, the credentials can send money out. Treat them like the keys to your till drawer.
- Store them on the server only, in configuration that is not part of the public website code and not in your code repository.
- Never send them by WhatsApp, SMS or plain email. Use a password manager share or another encrypted channel.
- Keep a register of who has seen them: which developer, which support company, which date.
- Regenerate them when a developer or supplier relationship ends, and after any suspected leak. Daraja lets you issue new keys for an app.
- Separate roles in the organisation portal. The person who reconciles statements does not need to approve B2C payments.
- Watch outbound payments. If you use B2C, set daily limits and alerts in your system so an error or abuse is noticed in hours, not at month end.
Payment records contain customers' names and phone numbers, which is personal data under the Data Protection Act 2019. The Office of the Data Protection Commissioner publishes guidance on obligations; protecting credentials and logs is part of meeting them.
After launch: the jobs that never end
An M-Pesa integration is not a fit-and-forget part like a door hinge. A few things keep needing attention, and it helps to agree in advance who owns each one.
| Ongoing task | Usually owned by | What goes wrong if ignored |
|---|---|---|
| Renewing the website's SSL certificate | Host or developer | Safaricom cannot deliver callbacks; payments stop reflecting |
| Updating portal users when staff leave | Owner | Ex-staff keep access; go-live or approvals get stuck |
| Changing initiator passwords used for B2C or queries | Owner with developer | Payouts and status checks start failing |
| Following Safaricom's API changes and notices | Developer | Old request formats are retired and calls fail |
| Monthly comparison of statement vs system records | Finance staff | Small gaps grow unnoticed into large ones |
| Moving the site to a new server | Developer | Callback URLs point to the old server |
Put this table in your support agreement. If nobody is named against a row, assume nobody will do it.
Questions to ask your developer
You do not need to read code to judge an M-Pesa integration. These questions surface most problems before they cost you money.
- Is the Daraja account in our company's name and email? Can I log in today?
- Where exactly are the credentials stored, and who can see them?
- When is an order marked paid: when the prompt is sent, or when Safaricom's callback confirms success?
- What happens if the callback never arrives? Do you query the transaction status automatically?
- Do you also register C2B confirmations, so customers who pay from the menu are captured?
- How are unmatched payments shown to my staff?
- If we use B2C, what limits and approvals stop a wrong payout?
- What did you test in production, and can I see the test log?
- Who do I call when payments stop reflecting on a public holiday, and what will it cost?
Good developers welcome these questions. Vague answers to questions 1, 3 and 9 are red flags.
A brief example
Imagine a Meru agrovet launching online orders. The owner creates the Daraja account with the business email, confirms the manager is the portal administrator, and books an afternoon for go-live. The developer handles the build and test plan. Credentials arrive to the owner, go into a password manager, and are shared once. A year later the agrovet changes developers; it regenerates keys in ten minutes and the new team carries on. That is how it should feel.
Where to go from here
If you are still choosing between going direct to Daraja and using an aggregator, read our comparison of M-Pesa payment options first. When Daraja is part of a wider system, such as a lending platform, fee portal or booking engine, our system development team builds the integration with the owner controls described here, and our web development service covers M-Pesa checkouts on ordinary business sites and stores.