Guides
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
| Situation | What you see | What to do |
|---|---|---|
| The customer hasn't answered yet | STK Push Query fails with error code 500.001.1001 | Not a failure. isPending is true; ask again later |
| Too many requests | HTTP 429 | Back off. isRateLimited is true and retryAfter says how long, when Daraja sends it |
| An API product isn't on your app | HTTP 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 credentials | HTTP 400 or 401 from the token request | Check the consumer key and secret, and that they match the environment |
| Invalid request | HTTP 400 with a Daraja error code | Usually 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.