How to Send SMS Through API
Alpha SMS API can be used by both GET and POST Method.
You can send SMS from your software or application by integrating Alpha SMS API. Just follow the code samples below to send SMS API from your applications. To obtain your API Key, please login to your SMS Panel & goto "My account" > "User configuration" you will get your api access token (Webservices token) here. Now you have to follow the instructions below.
API URL
http://alphasms.biz/index.php?app=ws
Send SMS (Example)
Example GET Method:
http://alphasms.biz/index.php?app=ws&u=username&h=a45a02791b2fe2fedb078c39fd83637a&op=pv&to=01979547393&msg=test+only
When succeeded Server will returns OK status message in JSON format:
{'data':[{'status':'OK','error':'0','smslog_id':'30','queue':'afb5f34575e30ec4efe4471cf5d1bee4','to':'01979547393'}],'error_string':null}
SMS API Codes samples in popular languages.
We have included code samples for sending SMS in PHP, C#, ASP.Net, Android, VB.NET etc. Choose your choice of Language from the tabs below to view SMS API Code samples.
- PHP
- C#
- ASP.NET
- ANDROID
- VB.NET
$username = "YourUserNameHere";
$hash = "YourTokenCodeHere"; //generate token from the control panel
$numbers = "017xxxxxxxx,018xxxxxxxx"; //Recipient Phone Number multiple number must be separated by comma
$message = "Simple text message.";
$params = array('app'=>'ws', 'u'=>$username, 'h'=>$hash, 'op'=>'pv', 'unicode'=>'1','to'=>$numbers, 'msg'=>$message);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://alphasms.biz/index.php?".http_build_query($params, '', '&'));
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:application/json", "Accept:application/json"));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($ch);
curl_close ($ch);
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;
namespace AlphaSMS{
class Program{
static void Main(string[] args){
string result = "";
WebRequest request = null;
HttpWebResponse response = null;
try{
String to = "016xxxxxxxx,017xxxxxxxx"; //Recipient Phone Number multiple number must be separated by comma
String username = "YourUserNameHere"; //Your Username
String hash_token = "YourTokenCodeHere"; //generate token from the control panel
String message = System.Uri.EscapeUriString("my messages"); //do not use single quotation (') in the message to avoid forbidden result
String url = "http://alphasms.biz/index.php?app=ws&op=pv&unicode=1&u=" + username + "&h=" + hash_token + "&to=" + to + "&msg=" + message;
request = WebRequest.Create(url);
// Send the 'HttpWebRequest' and wait for response.
response = (HttpWebResponse) request.GetResponse();
Stream stream = response.GetResponseStream();
Encoding ec = System.Text.Encoding.GetEncoding("utf-8");
StreamReader reader = new
System.IO.StreamReader(stream, ec);
result = reader.ReadToEnd();
Console.WriteLine(result);
reader.Close();
stream.Close();
} catch (Exception exp){
Console.WriteLine(exp.ToString());
} finally {
if (response != null)
response.Close();
}
}
}
}
<%
apiurl = "http://alphasms.biz/index.php?app=ws&op=pv&unicode=1"
username = "YourUserNameHere"
message = "Simple Text Message"
message = Server.urlencode(message)
numbers = "017xxxxxxxx,016xxxxxxxx"
url = apiurl & "&u=" YourUserNameHere "&h=" & hashtoken & "&to=" & numbers & "&msg=" & message
set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.open "GET", url, false
xmlhttp.send ""
msg = xmlhttp.responseText
response.write(msg)
set xmlhttp = nothing
%>
String username = "YourUserNameHere";
String hash_token = "YourTokenCodeHere";
//Single or Multiple mobiles numbers separated by comma
String to = "017xxxxxxxxx,016xxxxxxxx";
//Your message to send, Add URL encoding here.
String textmessage = "my message is here";
URLConnection myURLConnection=null;
URL myURL=null;
BufferedReader reader=null;
//encode the message content
String encoded_message=URLEncoder.encode(textmessage);
String apiUrl="http://alphasms.biz/index.php?app=ws&op=pv&unicode=1";
StringBuilder sgcPostContent= new StringBuilder(apiUrl);
sgcPostContent.append("u="+username);
sgcPostContent.append("h="+hash_token);
sgcPostContent.append("&to="+to);
sgcPostContent.append("&msg="+encoded_message);
apiUrl = sgcPostContent.toString();
try
{
//prepare connection
myURL = new URL(apiUrl);
myURLConnection = myURL.openConnection();
myURLConnection.connect();
reader= new BufferedReader(new InputStreamReader(myURLConnection.getInputStream()));
//read the output
String output;
while ((output = reader.readLine()) != null)
//print output
Log.d("OUTPUT", ""+output);
//Close connection
reader.close();
}
catch (IOException e)
{
e.printStackTrace();
}
Imports System.Web
Imports System.IO
Imports System.Net
Imports System.Text
Imports System.Resources
Public Class AlphaSMS
Public Function AlphaSMS()
Dim username = "YourUserNameHere"
Dim hashtoken = "YourTokenCodeHere"
Dim message = "Simple Text Message"
Dim numbers = "017xxxxxxxx"
Dim url As String = "http://alphasms.biz/index.php?app=ws&op=pv&unicode=1"
Dim strPost As String
strPost = url + "&u=" + username _
+ "&h=" + hashtoken _
+ "&to=" + numbers _
+ "&msg=" + WebUtility.UrlEncode(message)
Dim request As WebRequest = WebRequest.Create(strPost)
request.Method = "POST"
Dim byteArray As Byte() = Encoding.UTF8.GetBytes(strPost)
request.ContentType = "application/x-www-form-urlencoded"
request.ContentLength = byteArray.Length
Dim dataStream As Stream = request.GetRequestStream()
dataStream.Write(byteArray, 0, byteArray.Length)
dataStream.Close()
Dim response As WebResponse = request.GetResponse()
dataStream = response.GetResponseStream()
Dim reader As New StreamReader(dataStream)
Dim responseFromServer As String = reader.ReadToEnd()
Console.WriteLine(responseFromServer)
Console.ReadLine()
reader.Close()
dataStream.Close()
response.Close()
If responseFromServer.Length > 0 Then
Return responseFromServer
Else
Return CType(response, HttpWebResponse).StatusDescription
End If
End Function
End Class
SMS API Parameters
Listed in below are the API parameters available for individual tasks.
Name |
Description |
h |
Hash token, configured from User Configuration menu |
u |
Username |
op |
Operation or type of action (example: op=pv for Send SMS) |
to |
Destination numbers, username or #groupcode, may use commas |
nofooter |
Remove SMS footer (nofooter=1 will remove SMS footer.) |
msg |
Message (+ or %20 for spaces, urlencode for non ascii chars) |
schedule |
Schedule message delivery, format: YYYY-MM-DD hh:mm:ss |
unicode |
Whether message unicode or not (1=unicode, 0=not unicode) |