How to use the AllMySMS SMS HTTPS API
Our HTTP SMS API works by transmitting parameters in GET, or XML or JSON streams in POST (incoming and outgoing).
To send SMS or voice messages, XML or JSON streams containing the sending information must be transmitted to the platform.
In return, the platform will automatically return a response stream containing raw data and live XML or JSON streams (sending identifiers and acknowledgements of receipt). A unique identifier will be returned for each SMS, for subsequent acknowledgement of receipt.
A WebHook system, which can be configured in your customer area, enables you to retrieve acknowledgements of receipt and SMS responses in real time.
Address & Parameters (GET or POST)
https://api.www.allmysms.com/http/9.0/sendSms
The variable containing the stream must be named smsData
- login: customer login provided by www.allmysms.com
- apiKey: API key available from your account
- smsData: XML or JSON stream containing the message and telephone numbers
Documentation
- Download the latest version of the HTTPS API documentation : allmysms_api_https_v9.0_FR.pdf
PHP
.NET
JAVA
WINDEV
PERL
PYTHON
RUBY
C#
VB
PHP
<?php //config $url = 'https://api.www.allmysms.com/http/9.0/sendSms/'; $login = 'yourlogin'; //votre identifiant allmysms $apiKey = 'yourapikey'; //votre clé d'API allmysms $message = 'Envoi de SMS test avec AllMySMS.com'; //le message SMS $sender = 'allmysms'; //l’expéditeur, attention pas plus de 11 caractères alphanumériques $msisdn = '33612345678'; //numéro de téléphone du destinataire $smsData = "<DATA> <MESSAGE><![CDATA[" . $message . "]]></MESSAGE> <TPOA>" . $sender . "</TPOA> <SMS> <MOBILEPHONE>" . $msisdn . "</MOBILEPHONE> </SMS> </DATA>"; $fields = array( 'login' => $login, 'apiKey' => $apiKey, 'smsData' => $smsData, ); $fieldsString = http_build_query($fields); try { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, count($fields)); curl_setopt($ch, CURLOPT_POSTFIELDS, $fieldsString); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); // permet d’éviter le temps d'attente par défaut : 300 sec - optionnel curl_setopt($ch, CURLOPT_LOW_SPEED_LIMIT, 1024); // limite de detection des connexions lentes, en octets/sec (ici : 1 ko) - optionnel curl_setopt($ch, CURLOPT_LOW_SPEED_TIME, 1); // coupe la connexion si en dessous de CURLOPT_LOW_SPEED_LIMIT pendant plus de CURLOPT_LOW_SPEED_TIME - optionnel $result = curl_exec($ch); echo $result; curl_close($ch); } catch (Exception $e) { echo 'Api allmysms injoignable ou trop longue a repondre ' . $e->getMessage(); }
.NET
string url = "https://api.www.allmysms.com/http/[version]/sendSms/"; string login = "yourlogin"; string apiKey = "yourapikey"; Uri uri = new Uri(url); string data = "login="+login+"&apiKey="+apiKey+"&smsData=<DATA><MESSAGE><![CDATA[envoi de SMS en dotNet avec www.allmysms.com]]></MESSAGE><TPOA>EXPEDITEUR</TPOA><SMS><MOBILEPHONE>33612345678</MOBILEPHONE></SMS></DATA>"; byte[] Buffer = System.Text.Encoding.UTF8.GetBytes(data); HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri); request.Method = WebRequestMethods.Http.Post; request.ContentLength = Buffer.Length; request.ContentType = "application/x-www-form-urlencoded"; using (Stream writer = request.GetRequestStream()) { writer.Write(Buffer, 0, Buffer.Length); writer.Flush(); writer.Close(); } HttpWebResponse response = (HttpWebResponse)request.GetResponse(); StreamReader reader = new StreamReader(response.GetResponseStream()); string tmp = reader.ReadToEnd(); response.Close(); Response.Write(tmp);
JAVA
import java.io.*; import java.net.*; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathFactory; import org.w3c.dom.Document; public class sendSms { public static void main(String[] args) throws Exception { String phoneNumber = "33612345678"; String sender = "allmysms"; String message = URLEncoder.encode("Envoi de SMS en Java avec www.allmysms.com STOP au 36180", "UTF-8"); String login = "yourlogin"; String apiKey = "yourapikey"; String smsData = "<DATA><MESSAGE><![CDATA[["+message+"]]></MESSAGE><TPOA>"+sender+"</TPOA><SMS><MOBILEPHONE>"+phoneNumber+"</MOBILEPHONE></SMS></DATA>"; String url = "https://api.www.allmysms.com/http/[version]/sendSms/?login=" + login + "&apiKey=" + apiKey + "&smsData=" + smsData; // Send GET request URL client = new URL(url); URLConnection conn = client.openConnection(); InputStream responseBody = conn.getInputStream(); // Convert in XML document byte[] contents = new byte[1024]; int bytesRead=0; String strFileContents = null; while( (bytesRead = responseBody.read(contents)) != -1){ strFileContents = new String(contents, 0, bytesRead); } responseBody.close(); System.out.println(strFileContents); } }
WINDEV
PROCÉDURE Envoi_sms(Var_message, Var_nbr, Var_date) //Var_message > Message à envoyer //Var_nbr > Nombre de destinataires //Var_date > Date différée ou immédiate au format Dateheure //Sms_destinataire > Tableau contenant les expéditeurs LOCAL SMS_Date est une DateHeure = Var_date // Format Date heure SMS_Url est une chaîne = "https://api.www.allmysms.com/http/9.0/sendSms/" // L'url de allmysms SMS_Login est une chaîne = "xxxxxxx" // Identifiant fournit par Allmysms SMS_APIkey est une chaîne = "xxxxxxxxxxxxxx" // Clé de contrôle SMS_Data est un Variant // Données structuré SMS_Return est une chaîne = "JSON" // Format du retour SMS_Post est une chaîne // Variable du Post SI Var_date = "" ALORS SMS_Date = Maintenant() //Message converti au format UTF8 SMS_Data.DATA.MESSAGE = ChaîneVersUTF8(Var_message) //Ajout des destinataires POUR i = 1 À Var_nbr SMS_Data.DATA.SMS[i].MOBILEPHONE = Sms_destinataire[i] FIN //Mise en forme de la date SMS_Data.DATA.date = DateVersChaîne(SMS_Date,"AAAA-MM-JJ HH:MM:SS") SMS_Data.DATA.TPOA = "Expediteur" SMS_Post=ChaîneConstruit("login=%1&apiKey=%2&smsData=%3&returnformat=%4", SMS_Login, SMS_APIkey, VariantVersJSON(SMS_Data), SMS_Return) // Requête SI HTTPRequête(SMS_Url, "", "", SMS_Post)=Vrai ALORS vJSON est un Variant = JSONVersVariant(HTMLVersTexte(HTTPDonneRésultat(httpRésultat))) SI vJSON.status DANS ("100","101") ALORS Info("Votre SMS a bien été programmé") SINON Info("Erreur : ", vJSON.statusText, vJSON.status) FIN SINON Erreur(ErreurInfo()) FIN
PERL
my $userAgent = new LWP::UserAgent; $userAgent->protocols_allowed( [ 'https'] ); my $request = POST('https://api.www.allmysms.com/http/[version]/sendSms/', [ 'login' => 'yourlogin', 'apiKey' => 'yourapikey', 'smsData' => '<DATA><MESSAGE><![CDATA[envoi de SMS en perl avec www.allmysms.com]]></MESSAGE><TPOA>EXPEDITEUR</TPOA><SMS><MOBILEPHONE>33612345678</MOBILEPHONE></SMS></DATA>'], Content_Type => 'multipart/form-data'); my $response = $userAgent->request($request);
PYTHON
import urllib import xml.etree.ElementTree as ET smsData = '<![CDATA[envoi de SMS en python avec www.allmysms.com]]>EXPEDITEUR33612345678' urlbase = 'http://api.msinnovations.com/http/sendSms_v8.php' urlparam = urllib.urlencode([('clientcode','yourlogin'),('passcode','yourpasswd'),('smsData',smsData)]) response = ET.parse(urllib.urlopen(urlbase+urlparam)).getroot() print response.findtext('status')
RUBY
url = URI.parse('https://api.www.allmysms.com/http/[version]/sendSms/') req = Net::HTTP::Post.new(url.path) req.set_form_data({'login'=>'yourlogin','apiKey'=>'yourapikey','smsData'=>'<DATA><MESSAGE><![CDATA[envoi de SMS en windev avec www.allmysms.com]]></MESSAGE><TPOA>EXPEDITEUR</TPOA><SMS><MOBILEPHONE>33612345678</MOBILEPHONE></SMS></DATA>'}, '&') http = Net::HTTP.new(url.host, url.port) http.use_ssl = true res = http.start {|http| http.request(req) }
C#
url = URI.parse('https://api.www.allmysms.com/http/[version]/sendSms/') req = Net::HTTP::Post.new(url.path) req.set_form_data({'login'=>'yourlogin','apiKey'=>'yourapikey','smsData'=>'<DATA><MESSAGE><![CDATA[envoi de SMS en windev avec www.allmysms.com]]></MESSAGE><TPOA>EXPEDITEUR</TPOA><SMS><MOBILEPHONE>33612345678</MOBILEPHONE></SMS></DATA>'}, '&') http = Net::HTTP.new(url.host, url.port) http.use_ssl = true res = http.start {|http| http.request(req) }
VB
Option explicit Const login = "yourlogin" Const apiKey = "yourapikey" Dim smsData smsData = "<DATA><MESSAGE><![CDATA[envoi de SMS en vb avec www.allmysms.com]]></MESSAGE><TPOA>EXPEDITEUR</TPOA><SMS><MOBILEPHONE>33612345678</MOBILEPHONE></SMS></DATA>" EnvoiSms clientCode,passCode,smsData Sub EnvoiSms(clientCode, passCode, smsData) Dim xmlDoc,stUrl stUrl = "https://api.www.allmysms.com/http/[version]/sendSms/?login=" & _ login &"&apiKey=" & apiKey & "&smsData=" & Escape(smsData) Set xmlDoc=CreateObject("Microsoft.XMLDOM") xmlDoc.Async="false" if xmlDoc.Load(stUrl) and not xmldOC.selectSingleNode("/") is Nothing Then Msgbox "status = " & xmldOC.selectSingleNode("/").text else MsgBox "Pb sending", vbCritical End if End sub
SMS STATUS TABLE AFTER SENDING
100 | Le message a été envoyé |
101 | Le message a été programmé pour un envoi différé |
102 | Problème de connexion – Aucun compte ne correspond aux clientcode et passcode spécifiés |
103 | Crédit SMS épuisé. Veuillez re-créditer votre compte sur AllMySMS.com |
104 | Crédit insuffisant pour traiter cet envoi. A utiliser: XX Crédits, Disponibles: YY Crédits. Veuillez re-créditer votre compte sur AllMySMS.com |
105 | Flux XML Vide |
106 | Flux XML invalide ou incomplet après la balise |
107 | Flux XML invalide ou incomplet après la balise |
108 | Le code CLIENT donné dans le flux XML est incorrect, il doit correspondre au clientcode en majuscule |
109 | Flux XML invalide ou incomplet après la balise |
110 | Message non défini (vide) dans le flux XML |
111 | Le message dépasse 640 caractères |
112 | Flux XML invalide ou incomplet après la balise |
113 | Certains numéros de téléphone sont invalides ou non pris en charge |
114 | Aucun numéro de téléphone valide dans le flux. Veuillez-vous référer à la documentation en ligne pour connaitre les formats valides. |
115 | Flux XML invalide ou date mal formatée entre les balises et |
117 | Balise – Lien trop long, dépasse les 80 caractères |
118 | Le compte maître spécifié n’existe pas |
EXAMPLE OF AN SMS XML FLOW
<DATA> <MESSAGE><![CDATA[Votre message]]></MESSAGE> <DYNAMIC>2 (contiendra le nombre de paramètres variables du message)</DYNAMIC> (obligatoire si le message est variable) <CAMPAIGN_NAME>nom de campagne </CAMPAIGN_NAME> (option facultative) <DATE>date différée facultative ex.: 2011-11-05 15:10:00 </DATE> (option facultative) <TPOA>nom de l’émetteur (option facultative)</TPOA> <SMS> <MOBILEPHONE>33611111111</MOBILEPHONE> <PARAM_1>Parametre 1</PARAM_1> <PARAM_2>Parametre 2</PARAM_2> </SMS> <SMS> <MOBILEPHONE>33622222222</MOBILEPHONE> <PARAM_1>Parametre 1</PARAM_1> <PARAM_2>Parametre 2</PARAM_2> </SMS> </DATA>
EXAMPLE OF A JSON FLOW FOR SENDING AN SMS
{ "DATA": { "CAMPAIGN_NAME": "Nom de la campagne", "MESSAGE": "Votre message", "TPOA": "Nom de l’émetteur", "DYNAMIC": "2", "DATE": "2014-01-01 12:00:00", "SMS": [ { "MOBILEPHONE": "33611111111", "PARAM_1": "Parametre 1", "PARAM_2": "Parametre 2" }, { "MOBILEPHONE": "33622222222", "PARAM_1": "Parametre 1", "PARAM_2": "Parametre 2" } ] } }