Send SMS via our HTTP API works in just one line.
<?php
// First download the PHP class from Github (https://github.com/mobiletulip/messagebird-sms-api-php/archive/master.zip)
require_once 'lib/class.MessageBird.php';
// Set the Messagebird username and password, and create an instance of the MessageBird class
$sms = new MessageBird( 'username', 'password' );
// Set the sender: could be a number (16 numbers) or letters (11 characters)
$sms->setSender ( 'YourSender' );
// Add the destination mobile number.
// This method can be called several times to add more than one recipient for the same message
$sms->addDestination ( '31600000000' );
// Set a reference, optional
$sms->setReference ( '123456789' );
// Set a schedule date-time, optional
// $sms->setTimestamp('2014-01-01 10:02');
// Replace non GSM-7 characters by appropriate valid GSM-7 characters
// $sms->setReplacechars(false);
// If you want a dlr notification of the message sent to another url than that you have set on the website, you can use this parameter. Don't forget to set a reference!
// $sms->setDlrUrl('http://www.example.com/dlr_url.php');
// The message will be sent as a voice message and the gateway_id will be overwritten to 8, which is the voice gateway. (Dutch only for the moment)
// $sms->setVoice(true);
// Set the quality of the route that you want to use send the message.
// $sms->setGateway('quality');
// If $test is TRUE, then the message is not actually sent or scheduled, and there will be no credits deducted.
// $sms->setTest(true);
// Send the message to the destination(s)
$sms->sendSms ( 'This is a test message' );
echo "\nResponse:";
echo "\n" . $sms->getResponseCode ();
echo "\n" . $sms->getResponseMessage ();
echo "\n";
// First download the Java class (https://github.com/mobiletulip/messagebird-sms-api-java/archive/master.zip)
import com.messagebird.MessageBirdApi;
public class Example {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws Exception {
MessageBirdApi smsApi = new MessageBirdApi();
smsApi.authenticate("username", "password"); // authenticate with MessageBird SMS API
smsApi.setSender("YourSender"); // set the name or number where the message comes from
smsApi.addDestination("31600000001"); // add number to destination list, this function can be called multiple times for more receivers
smsApi.setReference("123456789"); // your unique reference
//smsApi.setTimestamp(2012, 2, 27, 11, 30); // only use if you want to schedule message
smsApi.send("This is a test message"); // send the message to the receiver(s)
System.out.println(smsApi.getResponseCode()); // print out the response code
System.out.println(smsApi.getResponseMessage()); // print out the response message
}
}
# First download the Python class (https://github.com/mobiletulip/messagebird-sms-api-python/archive/master.zip)
# Import the MessageBird Library which will send the message to our server
from MessageBird import MessageBird
# Set the MessageBird username and password and create an instance of the SmsCity class
smsApi = MessageBird('username', 'password')
# Set the sender: could be a number (16 numbers) or letters (11 characters)
smsApi.setSender('YourSender')
# Add the destination mobile number.
# This method can be called several times to add have more than one recipient for the same message
smsApi.addDestination('31600000000')
# Set a reference
smsApi.setReference('123456789')
# Send the message to the destination(s)
smsApi.sendSms('This is a test message')
# When using in the console, it will show you what the response was from our server
print 'Response:'
print smsApi.getResponseCode()
print smsApi.getResponseMessage()
<%
username = "your-username"
password = Server.urlencode("your-api-password")
body = "This is a test message"
body = Server.urlencode(body) <%-- // encode special characters --%>
sender = "YourSender"
destination = "31600000000" <%-- // more numbers can be added by seperating them with a comma (,) --%>
test = 0 <%-- // If test = 1, then the message is not actually sent or scheduled, and there will be no credits deducted. --%>
api_url = "http://api.messagebird.com/api/sms"
request_url = api_url & "?username=" & username & "&password=" & password & "&body=" & body &_
"&sender=" & sender & "&destination=" & destination & "&test=" & test
set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.open "GET", url, false
xmlhttp.send ""
msg = xmlhttp.responseText
response.write(msg)
set xmlhttp = nothing
%>
void Page_Load(Object Src, EventArgs E) {
api.Text = readHtmlPage("http://api.messagebird.com/api/sms");
}
private String readHtmlPage(string url)
{
String username = "your-username";
String password = "your-api-password";
String body = "This is a test message";
String body = body; /* encode special characters */
String sender = "YourSender";
String destination = "31600000000"; /* more numbers can be added by seperating them with a comma (,) */
String test = 0; /* If test = 1, then the message is not actually sent or scheduled, and there will be no credits deducted */
String result = "";
String strGet = "username=" + HttpUtility.UrlEncode(username) + "&password=" + HttpUtility.UrlEncode(password) +
"&body=" + HttpUtility.UrlEncode(body) + "&sender=" + HttpUtility.UrlEncode(sender) + "&destination=" + destination + "&test=" + test;
StreamWriter myRequest = null;
HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(url);
objRequest.Method = "POST";
objRequest.ContentLength = Encoding.UTF8.GetByteCount(strGet);
objRequest.ContentType = "application/x-www-form-urlencoded";
try{
myRequest = new StreamWriter(objRequest.GetRequestStream());
myRequest.Write(strGet);
}
catch (\Exception e)
{
return e.Message;
}
finally {
myRequest.Close();
}
HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()) )
{
result = sr.ReadToEnd();
// Close and clean up the StreamReader
sr.Close();
}
return result;
}
Imports System.IO
Imports System.Web
Private Function Send(
ByVal Body As String, _
ByVal Sender As String, _
ByVal Destination As String, _
ByVal Test As String
) As String
Const UserName As String = "your-username"
Const Password As String = "your-api-password"
Const ApiUrl As String = "http://api.messagebird.com/api/sms"
Dim strPost As String
strPost = "username=" + UserName _
+ "&password=" + System.Web.HttpUtility.UrlEncode(Password) _
+ "&body=" + System.Web.HttpUtility.UrlEncode(Body) _
+ "&sender=" + Sender _
+ "&destination=" + Destination _
+ "&test=" + Test
Dim byteArray As Byte() = Encoding.UTF8.GetBytes(strPost)
Dim request As WebRequest = WebRequest.Create(ApiUrl)
request.Method = "POST"
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()
reader.Close()
dataStream.Close()
response.Close()
If responseFromServer.Length > 0 Then
Return responseFromServer
Else
Return CType(response, HttpWebResponse).StatusDescription
End If
End Function
#!/usr/bin/perl -T
use strict;
use LWP::UserAgent;
use HTTP::Request::Common;
my $username = "your-username";
my $password = "your-api-password";
my $body = "This is a test message";
my $sender = "YourSender";
my $destination = "31600000000"; # more numbers can be added by seperating them with a comma (,)
my $test = 0; # If $test = 1, then the message is not actually sent or scheduled, and there will be no credits deducted
my $api_url = "http://api.messagebird.com/api/sms";
my $ua = LWP::UserAgent->new();
my $res = $ua->request
(
POST $api_url,
Content_Type => 'application/x-www-form-urlencoded',
Content => [ 'username' => $username,
'password' => $password,
'body' => $body,
'sender' => $sender,
'destination' => $destination,
'test' => $test,
]
);
if ($res->is_error) {
die "HTTP Error";
}
print "Response:\n\n" . $res->content . "\n\n";
require 'net/http'
require 'uri'
username = "your-username"
password = URI.escape("your-api-password")
body = "This is a test message"
body = URI.escape("body")
sender = "YourSender"
destination = "31600000000" # more numbers can be added by seperating them with a comma (,)
test = 0 # If test = 1, then the message is not actually sent or scheduled, and there will be no credits deducted
api_url = "http://api.messagebird.com/api/sms"
request_url = api_url + "?" + "username=" + username + "&password=" + password +
"&body=" + body + "&sender=" + sender + "&destination=" + destination + "&test=" + test
url = URI.parse(request_url)
full_path = (url.query.blank?) ? url.path : "#{url.path}?#{url.query}"
the_request = Net::HTTP::Get.new(full_path)
the_response = Net::HTTP.start(url.host, url.port) {
|http|
http.request(the_request)
}
puts(the_response.body)
The GO library is created by an external author.
The library can be found at: https://github.com/Grovespaz/sms
The documentation can be found at http://godoc.org/github.com/Grovespaz/sms