daraja-openapi

Errors and rate limits

Every SDK raises one error type for Daraja's answers, and a separate validation error for input it refuses to send.

Validation errors

Bad input fails on your server, before anything reaches Daraja: a phone number that isn't Kenyan, a description over 13 characters, an amount that isn't a whole number of shillings, a callback URL that isn't https://. The error names the field, so you can show it next to the form input.

Daraja errors

SituationWhat you seeWhat to do
The customer hasn't answered yetSTK Push Query fails with error code 500.001.1001Not a failure. isPending is true; ask again later
Too many requestsHTTP 429Back off. isRateLimited is true and retryAfter says how long, when Daraja sends it
An API product isn't on your appHTTP 401, "Invalid API call as no apiproduct match found"Add the product on the Daraja portal, then request a new token. isProductMissing is true
Wrong credentialsHTTP 400 or 401 from the token requestCheck the consumer key and secret, and that they match the environment
Invalid requestHTTP 400 with a Daraja error codeUsually a field Daraja rejects; the message names it

The STK Query 429

Daraja answers HTTP 429 to an STK Push Query sent a few seconds after the STK Push. The nightly sandbox run found this; Daraja's documentation doesn't mention it. Wait a few seconds before the first query, then back off on 429. waitForStkResult does both.

What never happens automatically

The SDKs never retry an STK Push or a payout. A retry after a timeout can't know whether the first request reached M-PESA, and a second prompt or a second payout costs your customer or you money. Retry deliberately, with the same originatorConversationId for payouts.

View the source of this page

Built by ByteGigs Labs. Apache 2.0. M-PESA, Daraja and Safaricom are trademarks of Safaricom PLC; this project is independent and not endorsed by Safaricom.