Sparrow is a comprehensive Mobile Money (MoMo) simulation system that provides REST and XML APIs for testing and learning mobile money services. This documentation covers all available endpoints and how to use them to build your own applications.
http://localhost:8080
cd /path/to/sparrow
mvn spring-boot:runhttp://localhost:8080/admin
# Add a user
curl -X POST http://localhost:8080/admin/addUser \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "phone=+1234567890&pin=1234&balance=100.00"
# Get all users
curl -X GET http://localhost:8080/api/users
# Send money
curl -X POST http://localhost:8080/admin/sendMoney \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "fromPhone=+1234567890&toPhone=+0987654321&amount=50.00"- URL:
/api/users - Method:
GET - Description: Retrieve all users in JSON format
- Response:
[ {"phone": "+1234567890"}, {"phone": "+0987654321"} ]
- URL:
/api/users/xml - Method:
GET - Description: Retrieve all users in XML format
- Response:
<users> <user><phone>+1234567890</phone></user> <user><phone>+0987654321</phone></user> </users>
- URL:
/api/users/balance - Method:
POST - Content-Type:
application/x-www-form-urlencoded - Parameters:
phone(string, required) - User's phone number
- Response:
{ "phone": "+1234567890", "balance": 100.50 } - Error Response:
{ "error": "User not found" }
- URL:
/api/users/transactions - Method:
POST - Content-Type:
application/x-www-form-urlencoded - Parameters:
phone(string, required) - User's phone number
- Response:
{ "phone": "+1234567890", "transactions": [ { "id": "T1642512345678", "description": "Sent to +0987654321", "amount": -50.00, "date": "2025-01-15 10:30:00" } ] }
- URL:
/admin/addUser - Method:
POST - Content-Type:
application/x-www-form-urlencoded - Parameters:
phone(string, required) - User's phone numberpin(string, required) - 4-digit PINbalance(number, required) - Initial balance
- Response: HTML page with success/error message
- URL:
/admin/sendMoney - Method:
POST - Content-Type:
application/x-www-form-urlencoded - Parameters:
fromPhone(string, required) - Sender's phone numbertoPhone(string, required) - Recipient's phone numberamount(number, required) - Amount to transfer
- Response: HTML page with transaction result
- URL:
/admin/buyAirtime - Method:
POST - Content-Type:
application/x-www-form-urlencoded - Parameters:
phone(string, required) - User's phone numberamount(number, required) - Airtime amount
- Response: HTML page with transaction result
- URL:
/admin/payWithMoMo - Method:
POST - Content-Type:
application/x-www-form-urlencoded - Parameters:
phone(string, required) - User's phone numbermerchant(string, required) - Merchant nameamount(number, required) - Payment amount
- Response: HTML page with transaction result
- URL:
/admin/payBill - Method:
POST - Content-Type:
application/x-www-form-urlencoded - Parameters:
phone(string, required) - User's phone numberbiller(string, required) - Biller nameamount(number, required) - Payment amount
- Response: HTML page with transaction result
- URL:
/admin/savingsLoans - Method:
POST - Content-Type:
application/x-www-form-urlencoded - Parameters:
phone(string, required) - User's phone numberaction(string, required) - "save" or "loan"amount(number, required) - Amount
- Response: HTML page with transaction result
- URL:
/admin/financialServices - Method:
POST - Content-Type:
application/x-www-form-urlencoded - Parameters:
phone(string, required) - User's phone numberservice(string, required) - "insurance" or "investment"amount(number, required) - Amount
- Response: HTML page with transaction result
- URL:
/admin/investInsure - Method:
POST - Content-Type:
application/x-www-form-urlencoded - Parameters:
phone(string, required) - User's phone numberaction(string, required) - "invest" or "insure"amount(number, required) - Amount
- Response: HTML page with transaction result
- URL:
/admin/addTransaction - Method:
POST - Content-Type:
application/x-www-form-urlencoded - Parameters:
phone(string, required) - User's phone numberdescription(string, required) - Transaction descriptionamount(number, required) - Transaction amount (positive for credit, negative for debit)
- Response: HTML page with transaction result
// Add a user
fetch('http://localhost:8080/admin/addUser', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: 'phone=+1234567890&pin=1234&balance=100.00'
})
.then(response => response.text())
.then(data => console.log(data));
// Get all users
fetch('http://localhost:8080/api/users')
.then(response => response.json())
.then(users => console.log(users));
// Get user balance
fetch('http://localhost:8080/api/users/balance', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: 'phone=+1234567890'
})
.then(response => response.json())
.then(data => console.log(data));
// Send money
fetch('http://localhost:8080/admin/sendMoney', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: 'fromPhone=+1234567890&toPhone=+0987654321&amount=50.00'
})
.then(response => response.text())
.then(data => console.log(data));import requests
# Add a user
response = requests.post('http://localhost:8080/admin/addUser', data={
'phone': '+1234567890',
'pin': '1234',
'balance': 100.00
})
print(response.text)
# Get all users
response = requests.get('http://localhost:8080/api/users')
print(response.json())
# Get user balance
response = requests.post('http://localhost:8080/api/users/balance', data={
'phone': '+1234567890'
})
print(response.json())
# Send money
response = requests.post('http://localhost:8080/admin/sendMoney', data={
'fromPhone': '+1234567890',
'toPhone': '+0987654321',
'amount': 50.00
})
print(response.text)# Add a user
curl -X POST http://localhost:8080/admin/addUser \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "phone=+1234567890&pin=1234&balance=100.00"
# Get all users (JSON)
curl -X GET http://localhost:8080/api/users
# Get all users (XML)
curl -X GET http://localhost:8080/api/users/xml
# Get user balance
curl -X POST http://localhost:8080/api/users/balance \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "phone=+1234567890"
# Get user transactions
curl -X POST http://localhost:8080/api/users/transactions \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "phone=+1234567890"
# Send money
curl -X POST http://localhost:8080/admin/sendMoney \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "fromPhone=+1234567890&toPhone=+0987654321&amount=50.00"
# Buy airtime
curl -X POST http://localhost:8080/admin/buyAirtime \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "phone=+1234567890&amount=20.00"
# Pay with MoMo
curl -X POST http://localhost:8080/admin/payWithMoMo \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "phone=+1234567890&merchant=SuperMarket&amount=75.00"
# Pay bill
curl -X POST http://localhost:8080/admin/payBill \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "phone=+1234567890&biller=ElectricityCompany&amount=120.00"
# Savings (save money)
curl -X POST http://localhost:8080/admin/savingsLoans \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "phone=+1234567890&action=save&amount=200.00"
# Request loan
curl -X POST http://localhost:8080/admin/savingsLoans \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "phone=+1234567890&action=loan&amount=500.00"
# Buy insurance
curl -X POST http://localhost:8080/admin/financialServices \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "phone=+1234567890&service=insurance&amount=150.00"
# Make investment
curl -X POST http://localhost:8080/admin/investInsure \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "phone=+1234567890&action=invest&amount=1000.00"{
"error": "User not found"
}
{
"error": "Insufficient funds"
}
{
"error": "Invalid amount"
}200- Success400- Bad Request (invalid parameters)404- Resource not found500- Internal server error
/admin- Main admin dashboard/admin/users- User management page/admin/services- Service operations page/admin/transactions- Transaction management page/admin/api-docs- API documentation page
- User Registration: Add users with initial balance
- Money Transfer: Send money between users
- Airtime Purchase: Buy airtime for phone numbers
- Bill Payments: Pay utilities and services
- Merchant Payments: Pay at stores and businesses
- Financial Services: Access insurance and investment services
- Savings & Loans: Save money or request loans
# 1. Create two users
curl -X POST http://localhost:8080/admin/addUser \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "phone=+1234567890&pin=1234&balance=1000.00"
curl -X POST http://localhost:8080/admin/addUser \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "phone=+0987654321&pin=5678&balance=500.00"
# 2. Check initial balances
curl -X POST http://localhost:8080/api/users/balance \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "phone=+1234567890"
# 3. Send money from user 1 to user 2
curl -X POST http://localhost:8080/admin/sendMoney \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "fromPhone=+1234567890&toPhone=+0987654321&amount=100.00"
# 4. Check balances after transfer
curl -X POST http://localhost:8080/api/users/balance \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "phone=+1234567890"
curl -X POST http://localhost:8080/api/users/balance \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "phone=+0987654321"
# 5. View transaction history
curl -X POST http://localhost:8080/api/users/transactions \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "phone=+1234567890"You can use these APIs to build a mobile money application:
- User Interface: Create forms for user registration and service operations
- API Integration: Use the REST endpoints to communicate with the backend
- Transaction History: Display user transactions and balances
- Service Menu: Implement USSD-style menus for different services
Build a web dashboard for monitoring:
- Real-time Updates: Poll the API for user and transaction data
- Analytics: Create charts showing transaction patterns
- Admin Controls: Manage users and transactions
- Reporting: Generate reports on system usage
Use Sparrow as a testing backend:
- Automated Tests: Write tests that use the API endpoints
- Load Testing: Test system performance with multiple users
- Integration Testing: Test your mobile money app against Sparrow
- Mock Services: Use for development when real services aren't available
sparrow/
├── src/main/java/
│ ├── adapters/ # Service adapters for different operations
│ ├── core/ # Core business logic
│ ├── handlers/ # HTTP request handlers
│ └── ui/ # Spring MVC controllers and UI
├── src/main/resources/
│ └── templates/ # Thymeleaf templates
├── pom.xml # Maven configuration
└── README.md # Project documentation
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
For questions or issues:
- Open an issue on GitHub
- Check the API documentation at
/admin/api-docs - Review the source code for implementation details