Need to programmatically send SMS from your application in Nepal? Whether you’re building OTP verification, transaction alerts, or automated sms marketing campaigns, the Sparrow SMS API provides a simple, reliable way to integrate SMS functionality.
This post is a comprehensive, practical guide for integrating our SMS API gateway. We’ll cover everything from getting your credentials to sending your first message, complete with copy-and-paste code examples for the most popular languages.
What is the Sparrow SMS API?
The Sparrow SMS API is a simple yet powerful HTTP-based interface that allows developers to connect their applications directly to our SMS gateway. Instead of logging into a dashboard to send messages, your software can send them automatically based on triggers you define, like a new user signup or a completed purchase.
Our API supports both sending messages (MT/Push) and receiving them (MO/Pull), making it a versatile tool for any communication need.
Why Developers in Nepal Choose the Sparrow SMS API
As a leading bulk SMS provider, we’ve built our API with developers in mind. Here’s why technical teams across Nepal trust Sparrow SMS.
Simplicity and Ease of Integration
Our platform is a standard RESTful API using GET/POST requests. There are no complex protocols to learn. If you can make an HTTP request, you can send an sms. It’s that easy.
Unmatched Reliability and Direct Connectivity
We have direct connections to major Nepali telecom operators like NTC and Ncell. This ensures high deliverability and speed, which is critical for time-sensitive messages like OTPs and critical alerts. This direct connectivity is what makes us a premier sms service provider.
Scalable for Any Application
Whether you’re sending 10 messages a day or managing a mass messaging campaign of 100,000, our API is built to handle the load. Our infrastructure is designed for high-volume bulk messaging, growing seamlessly with your business needs.
Comprehensive and Clear Documentation
We provide clear documentation and real-world code examples (like the ones in this post!) to get you up and running in minutes, not hours.
Getting Started: Your Pre-flight Checklist
Before you write any code, make sure you have the following essentials ready.
- A Sparrow SMS Account: You need an active account to get started. [Link to Sign Up]
- Your API Token: You can find this in your Sparrow SMS dashboard. Your token is your secret key. Keep it secure and never expose it in client-side code.
- Your Sender ID (Identity): You need an NTA-approved Sender ID, which you receive when you sign up. This will be your from parameter.
- A Development Environment: A place to run your PHP, Python, or Node.js code.
Core API Endpoints: Sending SMS and Checking Credits
Our API is built around a few core endpoints. Here are the two you’ll use most often.
Endpoint 1: Sending an SMS (/sms/)
This is the primary endpoint for our bulk sms service. It accepts both GET and POST requests, but we strongly recommend using POST for better security and reliability, especially when sending longer messages or to multiple numbers.
Mandatory Parameters:
| Parameter | Description | Example |
| token | Your unique API token from the dashboard. | Abc123xyz… |
| from | Your approved Sender ID. | YourBrand |
| to | A 10-digit mobile number, or comma-separated numbers for bulk sms. | 98xxxxxxxx,… |
| text | The URL-encoded message content you want to send. | Your OTP is… |
Endpoint 2: Checking Your Credit Balance (/credit/)
Before sending a large batch of messages, it’s good practice to programmatically check if you have enough credits. This simple GET endpoint lets you do just that.
Mandatory Parameters:
| Parameter | Description | Example |
| token | Your unique API token from the dashboard. | Abc123xyz… |
Integration Examples: Send Your First SMS in 5 Minutes
Here are practical, copy-and-paste examples to get you sending messages immediately.
PHP Integration (using cURL)
PHP is one of the most popular languages for web development in Nepal. Here’s how you can send an SMS using the robust cURL extension.
PHP
<?php
$token = 'YOUR_API_TOKEN';
$from = 'YOUR_SENDER_ID';
$to = '98xxxxxxxx,98yyyyyyyy';
$text = 'Hello from Sparrow SMS API! This is a test message.';
$args = http_build_query(array(
'token' => $token,
'from' => $from,
'to' => $to,
'text' => $text
));
$url = "http://api.sparrowsms.com/v2/sms/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($statusCode == 200) {
echo "SMS sent successfully! Response: " . $response;
} else {
echo "Failed to send SMS. HTTP Status Code: " . $statusCode . " Response: " . $response;
}
?>
Python Integration (using the requests library)
For Python developers, the requests library makes sending an SMS incredibly clean and simple. If you don't have it, install it first: pip install requests.
Python
import requests
api_url = "http://api.sparrowsms.com/v2/sms/"
payload = {
'token': 'YOUR_API_TOKEN',
'from': 'YOUR_SENDER_ID',
'to': '98xxxxxxxx,98yyyyyyyy',
'text': 'Hello from Sparrow SMS API! This is a test message.'
}
try:
response = requests.post(api_url, data=payload)
response.raise_for_status() # Raises an HTTPError for bad responses (4xx or 5xx)
print("SMS sent successfully!")
print("Response:", response.json())
except requests.exceptions.HTTPError as errh:
print(f"Http Error: {errh}")
print("Response:", response.text)
except requests.exceptions.RequestException as err:
print(f"Something went wrong: {err}")
Node.js Integration (using axios)
For JavaScript developers on the server-side, axios is a popular promise-based HTTP client. Install it with npm install axios.
JavaScript
const axios = require('axios');
const querystring = require('querystring');
const apiUrl = 'http://api.sparrowsms.com/v2/sms/';
const payload = {
token: 'YOUR_API_TOKEN',
from: 'YOUR_SENDER_ID',
to: '98xxxxxxxx,98yyyyyyyy',
text: 'Hello from Sparrow SMS API! This is a test message.'
};
axios.post(apiUrl, querystring.stringify(payload))
.then(response => {
console.log('SMS sent successfully!');
console.log('Response:', response.data);
})
.catch(error => {
console.error('Failed to send SMS.');
if (error.response) {
// The request was made and the server responded with a status code
// that falls out of the range of 2xx
console.error('Status:', error.response.status);
console.error('Data:', error.response.data);
} else {
// Something happened in setting up the request that triggered an Error
console.error('Error:', error.message);
}
});
Understanding API Responses and Error Handling
A successful API call is only half the story. You need to know how to handle both success and failure in your code.
The Success Response (Status Code 200)
A 200 OK status means our server has accepted your request and queued the messages for delivery. The response body will contain more details.
{
"count": 2,
"response_code": 200,
"response": "2 mesages has been queued for delivery"
}
Common Error Responses (Status Code 403)
If something goes wrong with your request parameters, you’ll likely receive a 403 Forbidden status. Here are the most common causes.
| response_code | Message | Common Cause & Solution |
| 1002 | Invalid Token | Your API token is incorrect or has been revoked. Double-check it in your dashboard. |
| 1008 | Invalid Sender | The from parameter doesn’t match an approved Sender ID on your account. |
| 1011 | No valid receiver | The to parameter contains invalid or incorrectly formatted phone numbers. Ensure 10 digits. |
| 1013 | Insufficient Credits | Your account doesn’t have enough credits to send the requested number of SMS. |
Advanced: Receiving SMS (Mobile Originated)
Our API also supports two way messaging. You can receive messages sent to your dedicated shortcode or number, which is perfect for building interactive services like polls, keyword-based subscriptions, or two-way support channels.
This works via a webhook: you provide a URL in your dashboard, and when an SMS comes in, our system sends a GET request to your URL with the message details (from, to, text, keyword). Your application can then process this and send back a reply.
For a detailed guide on setting up incoming SMS, please refer to our full API documentation.
Ready to Build? Start Integrating Today
The Sparrow SMS API is simple, reliable, and powerful. It’s the fastest way to add professional SMS capabilities to your application in Nepal.
Have a question or need help with a specific integration? Our developer support team is here to help. Sign up for your free Sparrow SMS account today and get your API token to start building.

















