EasySendSMS API
EasySendSMS.com provides a powerful REST API that allows businesses and developers to send and manage SMS communications, perform HLR queries, and validate phone numbers with ease. This API is designed to integrate seamlessly with your applications, offering a reliable way to enhance your communication capabilities. In this blog, we will explore how to utilize the EasySendSMS REST API for sending SMS messages, conducting HLR lookups, and validating phone numbers using your API key for authentication.
Before you can start sending SMS or performing number validations, you need to set up your account and obtain your API key. Here’s a quick guide on how to get started:
Sign Up and Obtain Your API Key:
Set Up Your Environment:
HttpClient
in .NET, requests
in Python, or Axios
in JavaScript.Understand the Documentation:
Sending SMS is one of the core functionalities of the EasySendSMS API. Here’s a detailed look at how to send SMS using the REST API.
The endpoint for sending an SMS is:
POST https://restapi.easysendsms.app/v1/rest/sms/send
Your API requests must include the following headers:
application/json
application/json
All SMS requests should use the application/json
content type, and the request body should be formatted in JSON. The following parameters are required:
from: The sender's name or number. For numeric values, the max length is 15 characters. For alphanumeric values, the max length is 11 characters. If you want the sender's name to appear with a plus sign, prefix it in the request (URL encoded).
to: The recipient’s mobile number in international format, without the plus sign or leading zeros. You can send messages to multiple numbers by separating them with commas (maximum 30 numbers per request).
text: The message content. It can be plain text or Unicode, with a maximum length of 5 parts (concatenated messages).
type: The message type. Use 0
for plain text (GSM 3.38 encoding) and 1
for Unicode.
scheduled (optional): The scheduled date and time for sending the message in ISO 8601 format. The time is in UTC.
Here’s an example of how to send an SMS using the API in Python:
import requests
headers = {
'apikey': 'YOUR_API_KEY',
'Content-Type': 'application/json',
'Accept': 'application/json'
}
data = {
"from": "YourSenderName",
"to": "12345678900,19876543210",
"text": "Hello, this is a test message!",
"type": "0"
}
response = requests.post('https://restapi.easysendsms.app/v1/rest/sms/send', headers=headers, json=data)
print(response.json())
The API returns a JSON response indicating the success or failure of your request. The response will include message IDs for successful sends or error codes if the request fails.
Example Success Response:
{
"status": "OK",
"scheduled": "Now",
"messageIds": [
"OK: 69991a73-a560-429f-9c5a-3251dc1522bb"
]
}
Example Error Response:
{
"error": 4012,
"description": "Invalid mobile number."
}
HLR (Home Location Register) lookup is used to verify the status of a mobile number, including whether it is active, its network operator, and whether it is currently roaming. This can help reduce SMS delivery failures.
To perform an HLR lookup, send a request to:
POST https://restapi.easysendsms.app/v1/rest/hlr/query
The request body should be in JSON format and include the following parameter:
Here’s how to perform an HLR lookup in PHP:
$apiKey = "YOUR_API_KEY";
$url = "https://restapi.easysendsms.app/v1/rest/hlr/query";
$data = array(
'number' => '19876543210'
);
$options = array(
'http' => array(
'header' => "apikey: $apiKey\r\n" .
"Content-Type: application/json\r\n",
'method' => 'POST',
'content' => json_encode($data),
),
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) { /* Handle error */ }
var_dump($result);
The response will provide details about the mobile number, including:
Example Success Response:
{
"12345678900": {
"number": "12345678900",
"country": "United States of America",
"err_desc": "Live",
"operatorName": "First Communications",
"type": "Landline",
"mccmnc": "-",
"roaming": "False",
"err_code": "0",
"status": "Delivered",
"ported": "True"
}
}
The Number Validation (NV) feature allows you to validate the format and status of a phone number before sending an SMS. This is especially useful for ensuring that messages are sent to valid and reachable numbers.
To validate a number, use the following endpoint:
POST https://restapi.easysendsms.app/v1/rest/nv/query
The request body should include:
Here’s how to perform number validation using the API in C#:
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
var client = new HttpClient();
client.DefaultRequestHeaders.Add("apikey", "YOUR_API_KEY");
var content = new StringContent("{\"number\":\"19876543210\"}", Encoding.UTF8, "application/json");
var response = await client.PostAsync("https://restapi.easysendsms.app/v1/rest/nv/query", content);
var responseString = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseString);
}
}
The validation response will include the status of the number, the country, the network operator, and other relevant information.
Example Success Response:
{
"results": [
{
"status": "VALID",
"country": "United States of America",
"iso3166_2": "US",
"cc": "1",
"netName": "",
"mcc": "310",
"mnc": "316",
"operator": "",
"type": "FIXED",
"netType": "",
"msisdn": "12345678900"
}
]
}
To make the most of the EasySendSMS API, it’s important to follow best practices:
API Key Security: Keep your API key secure and never expose it in client-side code or public repositories.
Rate Limiting: Respect the API’s rate limits to avoid your requests being rejected. Implement a queuing system in your application to manage the rate at which requests are sent.
Error Handling: Implement robust error handling to manage different types of errors, such as invalid numbers, insufficient credits, or network issues.
Monitor Usage: Regularly monitor your API usage and SMS credits to avoid unexpected disruptions.
Use Valid Numbers: Validate phone numbers before sending SMS to reduce the number of failed deliveries.
The EasySendSMS REST API is a comprehensive tool for businesses and developers who need to integrate SMS functionality, perform HLR lookups, and validate phone numbers in their applications. By following the steps and best practices outlined in this blog, you can ensure that your communication is effective, reliable, and secure.
For more detailed information, visit the EasySendSMS Developers Page. This resource provides extensive documentation and examples to help you make the most of the API. Whether you’re sending marketing messages, transactional alerts, or validating phone numbers, EasySendSMS offers the tools you need to succeed.