Skip to content
M-Pesa & Payments

Safaricom Daraja API Explained for Business Owners

8 min read

On this page
  1. What Daraja is
  2. APIs that matter: STK push, C2B, B2C and status
  3. Sandbox vs production
  4. Going live: what the owner must do
  5. Keeping API credentials safe
  6. After launch: the jobs that never end
  7. Questions to ask your developer
  8. Where to go from here

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.

ServiceDirectionUsed for
M-Pesa Express (STK push)Customer pays you, prompted by your systemWebsite and app checkouts, deposits, invoice "pay now" buttons
C2B (customer to business)Customer pays you from the M-Pesa menuGetting instant notice of manual Paybill or Till payments so they post automatically
B2C (business to customer)You pay customersRefunds, loan disbursements, salaries, winnings, agent commissions
Transaction statusQueryChecking the outcome of a payment your system missed
Account balance and reversalQuery / correctionBalance 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

  1. Confirm the shortcode is registered to the business and active.
  2. 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.
  3. Create the Daraja account under a business email you control, such as payments@yourcompany.co.ke, not the developer's personal Gmail.
  4. 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.
  5. 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.
  6. 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 taskUsually owned byWhat goes wrong if ignored
Renewing the website's SSL certificateHost or developerSafaricom cannot deliver callbacks; payments stop reflecting
Updating portal users when staff leaveOwnerEx-staff keep access; go-live or approvals get stuck
Changing initiator passwords used for B2C or queriesOwner with developerPayouts and status checks start failing
Following Safaricom's API changes and noticesDeveloperOld request formats are retired and calls fail
Monthly comparison of statement vs system recordsFinance staffSmall gaps grow unnoticed into large ones
Moving the site to a new serverDeveloperCallback 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.

  1. Is the Daraja account in our company's name and email? Can I log in today?
  2. Where exactly are the credentials stored, and who can see them?
  3. When is an order marked paid: when the prompt is sent, or when Safaricom's callback confirms success?
  4. What happens if the callback never arrives? Do you query the transaction status automatically?
  5. Do you also register C2B confirmations, so customers who pay from the menu are captured?
  6. How are unmatched payments shown to my staff?
  7. If we use B2C, what limits and approvals stop a wrong payout?
  8. What did you test in production, and can I see the test log?
  9. 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.

FAQ

Questions about this topic

Creating a Daraja account and testing in the sandbox does not cost anything. In production, you pay the normal M-Pesa charges that apply to your Till or Paybill and the transaction type, such as receiving customer payments or sending money out through B2C. Safaricom publishes its business tariffs, so check the current figures there rather than relying on older articles.

No. Daraja works with business shortcodes, meaning Till numbers and Paybill numbers registered to an organisation. Personal lines and Pochi la Biashara are not supported for API integration. If you currently collect on a personal number, apply for a Till or Paybill first; it also keeps business money separate for your records and tax returns.

If the Daraja account, the organisation portal admin role and the credentials are held by the business, very little. A new developer can be given access, credentials can be regenerated, and work continues. If the old developer created everything under their own email, you may face delays recovering control. That is why owners should create and hold these accounts from day one.

Ready to build something great?

Tell us what you need. We'll come back with a fixed-scope proposal within one business day.

Start a conversation