MTN Mobile Money API Tutorial for Beginners (Rwanda, 2026)
This tutorial walks you through your first MTN MoMo API integration step by step: (1) create a developer account at the MoMo Developer Portal, (2) generate sandbox API credentials, (3) set up a Node.js project, (4) authenticate and get an access token, (5) send a Request to Pay, (6) handle the callback, (7) verify the transaction status. By the end, you will have processed a simulated MoMo payment in the sandbox environment.
Before You Start
This tutorial assumes you have basic knowledge of JavaScript and Node.js. You should be comfortable creating a simple Express server and sending HTTP requests. If you are not there yet, complete the first five steps of our coding learning roadmap before attempting this tutorial.
You will need:
- Node.js installed on your computer (version 18 or later)
- A code editor (VS Code recommended)
- A terminal or command prompt
- An internet connection
- Optionally, ngrok or a similar tunneling tool for callback testing
This tutorial covers the sandbox environment only. For going live with real transactions, see our full MoMo integration guide.
Step 1: Create Your MoMo Developer Account
Go to the MTN MoMo Developer Portal. Create an account with your email address. After verifying your email, log in and navigate to the API products section.
Subscribe to the Collections product. This is the API that lets you receive payments from customers. You will receive a primary key and secondary key for the sandbox environment. Save these. You will use them in every API call.
The sandbox environment is free and does not require any business verification. You can start building immediately.
Step 2: Set Up Your Node.js Project
Create a new project directory and initialize it:
mkdir momo-integration
cd momo-integration
npm init -y
npm install express axios dotenv
Create a .env file for your credentials:
MOMO_SUBSCRIPTION_KEY=your_primary_key_here
MOMO_API_BASE_URL=https://sandbox.momodeveloper.mtn.com
MOMO_CALLBACK_URL=https://your-ngrok-url.ngrok.io/callback
PORT=3000
Never commit your .env file to Git. Add it to .gitignore immediately. Leaking API credentials is one of the most common security mistakes developers make.
Step 3: Authenticate and Get an Access Token
MoMo API authentication involves creating an API user and key in the sandbox, then using those to get an access token. The access token is what you include in every subsequent API call.
The sandbox authentication flow is:
- Create an API user. POST to the sandbox provisioning endpoint with a reference ID (a UUID you generate) and your callback host.
- Create an API key. POST to get a key for the user you just created.
- Get an access token. Use Basic auth with your API user ID and API key to get a Bearer token.
In production, the API user and key are provided during the approval process. The sandbox requires you to create them programmatically.
This three-step authentication may feel complex compared to a simple API key. It is. Mobile money APIs handle real money, so the authentication is deliberately more secure. Once you have the access token, the rest of the integration is straightforward HTTP requests.
Step 4: Send a Request to Pay
With your access token, you can now request a payment. This is the core of the Collections API.
You send a POST request with:
- Amount: The payment amount (e.g., "1000" for RWF 1,000)
- Currency: "RWF" for Rwandan Franc
- External ID: Your unique reference for this transaction
- Payer: The customer's phone number (MSISDN format)
- Payer message: What the customer sees on their phone
- Payee note: Your internal note for the transaction
In the sandbox, the payment is simulated. No real MoMo prompt appears on any phone. The sandbox automatically simulates the customer confirming the payment.
After sending the request, the API returns a 202 Accepted status. This means "I received your request, but the payment is not complete yet." The result comes via callback or polling. This asynchronous flow is the fundamental difference between mobile money and payment gateways like Stripe, where the result is immediate.
Step 5: Handle the Callback
When the transaction completes (or fails), MoMo sends a POST request to your callback URL with the transaction result. Your server needs to:
- Have a route that accepts POST requests at your callback path (e.g.,
/callback). - Parse the incoming JSON payload.
- Verify the transaction reference matches one you initiated.
- Update your application state based on the result (mark order as paid, send confirmation, etc.).
- Respond with a 200 OK to acknowledge receipt.
The localhost problem: During development, your Express server runs on localhost:3000. MoMo cannot reach localhost. You need a tunneling tool like ngrok to create a public URL that forwards to your local server. Run ngrok http 3000 and use the generated URL as your callback URL in the API request.
This is the step where most beginners get stuck. If your callback is not receiving requests, check: Is your server running? Is ngrok active? Does your callback URL match exactly? Is your server responding with 200? Debug one variable at a time.
Step 6: Verify Transaction Status (Fallback)
Callbacks can fail. Networks drop. Servers restart. You should always have a fallback: polling the transaction status endpoint with your reference ID. This returns the current status of the transaction regardless of whether the callback succeeded.
In a production application, implement both: process the callback when it arrives, and poll for status if the callback has not arrived within a reasonable timeout (30 to 60 seconds). This dual approach ensures you never miss a transaction result.
When your sandbox integration handles both callbacks and polling correctly, you have a solid MoMo integration. The remaining work is building it into your application's UI and business logic, then testing thoroughly before going to production.
Where to Go From Here
This tutorial covered the basic sandbox flow. To build a production-ready integration, you also need:
- Error handling for every failure mode (network errors, insufficient funds, wrong PIN, timeout). See our guide to common MoMo API errors.
- Transaction logging and reconciliation.
- Security: validating callbacks, storing credentials safely, using HTTPS.
- Production approval from MTN.
If you want to learn mobile money integration in a structured, mentored format with all of these topics covered, McTaba's M-Pesa Integration course (KES 9,999, approximately RWF 100,000) teaches the complete pattern. The course uses M-Pesa and Airtel Money as the teaching platform, but the callback architecture, error handling, and production deployment process you learn transfers directly to MoMo. You learn the pattern once, then adapt it to whichever API your project needs.
Key Takeaways
- ✓The MoMo Developer Portal provides a sandbox where you can simulate payments without real money. Start here, not in production.
- ✓The core integration involves four API calls: create API user, create API key, get access token, and request to pay. Everything else builds on these.
- ✓Callback handling is the part that trips up most beginners. Your server must be publicly accessible for MoMo to send transaction results back to you.
- ✓Use ngrok or a similar tunneling tool during development to expose your local server to the internet for callback testing.
- ✓This tutorial uses Node.js and Express, but the concepts apply to any language. The HTTP requests are the same regardless of your tech stack.
Frequently Asked Questions
- Do I need a Rwandan phone number to test MoMo API?
- No. The sandbox simulates phone interactions. You provide a test phone number in your API request, and the sandbox automatically simulates the confirmation. No real phone or SIM card is needed for development and testing.
- How long does the sandbox approval take?
- Sandbox access is immediate. You create a developer account, subscribe to the API product, and get your keys within minutes. No approval process is needed for the sandbox. Production approval takes longer and involves a review.
- Can I use this tutorial for MoMo APIs in other countries?
- The MTN MoMo API is similar across countries where MTN operates (Rwanda, Uganda, Ghana, Cameroon, and others). The API structure and authentication flow are the same. Currency codes and some regulatory requirements differ. This tutorial focuses on Rwanda (RWF), but the code applies broadly.
Ready to build real-world apps?
Join the McTaba Labs full-stack marathon (4 months full-time · 6 months part-time). Learn M-Pesa, USSD, and WhatsApp engineering while shipping 8 production apps.
Apply to the McTaba Marathon