ES

API for sending SMS http/GET

The API SMS http/GET is designed for technicians and customers who want to connect their applications to LabsMobile's SMS messaging platform.

The functionalities of the SMS http/GET API are:

This documentation explains in detail the process of integration and automation of these functionalities.

To start an integration with the http/GET API the following requirements are essential:

  • A LabsMobile account associated with a username (registration email). Create an account here.
  • API token used as password and generated from the API Settings section of your account.
  • URL of the http/GET API endpoint and the values of the parameters to make the request.

To be taken into account

RecommendationWe recommend using the API SMS http/POST because it includes more functionality, improves security and performance.

LabsMobile's API http/GET is a REST API that uses the HTTP GET protocol with a common base URL for all requests: https://api.labsmobile.com/get.

It is recommended to use a URL that includes the HTTPS protocol in any version of our API.


Authentication

In the SMS http/GET API there are two possible authentication methods:

  • Basic Auth HTTP. This type of authentication consists of username:tokenapi credentials that are included in the HTTP request header encoded in base64().
    Example of authentication header value:
    Authorization: Basic 9yewaXic21vYmlsZqS5jmSk04enFTbUU=

  • GET parameters. The credentials are sent in two parameters username and password that are included in the request URL.
    Example of authentication with GET parameters:
    ?username=myusername&password=tokenapi

Important We recommend using the Basic Auth method because it is not secure to transmit credentials in GET parameters.


Configuration and filters

The following are important configuration variables and security aspects in an integration with the SMS http/GET API:

  • IP address from which messages will be sent. If this option is enabled, only requests from the list of IP addresses entered will be accepted. This functionality is optional, by default messages will be accepted from any IP.
  • Default sender (default LABSMOBILE). Only some operators allow dynamic, alphanumeric-valued mapping of the sender field.
  • Daily message limit, by default 100,000 sms/day.
  • Message limit per batch, default 10,000 sms/request.
  • Country filter, so that only messages from a list of countries are processed.
  • Anti-duplication filter, to avoid sending identical messages to the same recipient.

All these parameters can be activated and modified in the API Settings and Account Preferences.

Important A maximum of 10 requests per second is established. Misuse, abuse or a higher volume of requests will result in a temporary or permanent blocking of the account and/or IP address.

Recommendation We recommend activating the Automatic Top-Ups so that there are always credits available in the account and the SMS sending service is not interrupted.


Sending SMS messages

Petition for sending SMS messages individually or in bulk.

With this functionality, messages can be sent in real time or scheduled for a specific day and time. In addition, other parameters such as sender, label, identifier, simulated mode, etc. can be added.

ENDPOINT

GET https://api.labsmobile.com/get/send

  • Expand all

    PARAMETERS

    The parameters or data are sent in http/GET variables in the request URL itself. The values and functionality of all parameters are described below:

  • RESULT

    The result of any SMS http/GET API request is obtained in XML format with the root element <response> and the following child elements:

Individual sending
  curl --location 'http://api.labsmobile.com/get/send.php?username=myUsername&password=myToken&msisdn=12015550123&message=Your%20verification%20code%20is%20123'
                
  #include <stdio.h> 
  #include <curl/curl.h> 

  int main(void)
  {
      CURL *curl;
      CURLcode res;

      char *username = "myUsername";
      char *token = "myToken";
      char *msisdn = "12015550123";
      char *message = "Your verification code is 123";

      char *encoded_username = curl_easy_escape(curl, username, 0);
      char *encoded_message = curl_easy_escape(curl, message, 0);

      char url[500]; 
      sprintf(url, "http://api.labsmobile.com/get/send.php?username=%s&password=%s&msisdn=%s&message=%s&test=1", encoded_username, token, msisdn, encoded_message);

      curl = curl_easy_init();
      if (curl)
      {
          curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET");
          curl_easy_setopt(curl, CURLOPT_URL, url);
          curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
          curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
          res = curl_easy_perform(curl);
          if (res != CURLE_OK)
          {
              fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
          }
      }
      curl_free(encoded_username);
      curl_free(encoded_message);
      curl_easy_cleanup(curl);
      return 0;
  }
              
  using System;
  using RestSharp;

  namespace SendGetUni
  {
    class Program
    {
      static void MainSend(string[] args)
      {
        string username = "myUsername";
        string token = "myToken";
        string msisdn = "12015550123";
        string message = "Your verification code is 123";

        var client = new RestClient("https://api.labsmobile.com");
        var request = new RestRequest("/get/send.php", Method.Get);

        request.AddParameter("username", username);
        request.AddParameter("password", token);
        request.AddParameter("msisdn", msisdn);
        request.AddParameter("message", message);

        RestResponse response = client.Execute(request);
        if (response.ErrorException != null)
        {
          Console.WriteLine("Error: " + response.ErrorException.Message);
        }
        else
        {
          Console.WriteLine("Response content: " + response.Content);
        }
      }
    }
  }
              
  import com.mashape.unirest.http.HttpResponse;
  import com.mashape.unirest.http.Unirest;
  import com.mashape.unirest.http.exceptions.UnirestException;

  import java.io.UnsupportedEncodingException;
  import java.net.URLEncoder;

  public class App {
    public static void main(String[] args) throws UnirestException, UnsupportedEncodingException {
      String username = "myUsername";
      String token = "myToken";
      String message = "Your verification code is 123";
      String[] msisdn = {"12015550123"};

      String url = "http://api.labsmobile.com/get/send.php?username=" +
              URLEncoder.encode(username, "utf-8") +
              "&password=" + URLEncoder.encode(token, "utf-8") +
              "&message=" + URLEncoder.encode(message, "utf-8") +
              "&msisdn=" + URLEncoder.encode(String.join(",", msisdn), "utf-8");

      Unirest.setTimeouts(0, 0);
      HttpResponse<String> response = Unirest.get(url).asString();
      System.out.println("Status code: " + response.getBody());
    }
  }
              
<?php 
  $curl = curl_init();

  $username = "myUsername";
  $token = "myToken";
  $msisdn = array(12015550123);
  $message = "Don't miss our Sale! Use code XXXX123 for 20% off.";

  $url = 'http://api.labsmobile.com/get/send.php?';
              $url .= 'username='.  urlencode($username) .'&';
              $url .= 'password='.  urlencode($token) .'&';
              $url .= 'msisdn=' .  urlencode(json_encode($msisdn)) .'&';
              $url .= 'message=' .  urlencode($message);
  curl_setopt_array($curl, array(
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => '',
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 0,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => 'GET',
  ));

  $response = curl_exec($curl);

  curl_close($curl);
  echo $response;
              
  import requests, urllib.parse

  data = {
      'username':'myUsernmae',
      'password': 'myToken',
      'msisdn': '[12015550123]',
      'message':'Your verification code is 123'
  }

  url = "http://api.labsmobile.com/get/send.php?"+urllib.parse.urlencode(data, doseq=True)
  payload = {}
  headers = {}

  response = requests.request("GET", url, headers=headers, data=payload)

  print(response.text)
              
  const axios = require('axios');

  const username = "myUsername";
  const token = "myToken";
  const message = "Your verification code is 123";
  const msisdns = ["12015550123"];

  let config = {
    method: 'get',
    maxBodyLength: Infinity,
    url: `http://api.labsmobile.com/get/send.php?username=${encodeURIComponent(username)}&password=${encodeURIComponent(token)}&message=${encodeURIComponent(message)}&msisdn=${encodeURIComponent(JSON.stringify(msisdns))}`
  };

  axios.request(config)
  .then((response) => {
    console.log(JSON.stringify(response.data));
  })
  .catch((error) => {
    console.log(error);
  });

              
  require "uri"
  require "net/http"

  url = URI("http://api.labsmobile.com/get/send.php")

  data = {
    'username' => 'myUsername',
    'password' => 'myToken',
    'msisdn' => '[12015550123]',
    'message' => 'Your verification code is 123'
  }

  url.query = URI.encode_www_form(data)
  https = Net::HTTP.new(url.host, url.port)
  request = Net::HTTP::Get.new(url)

  response = https.request(request)
  puts response.read_body
              
Multiple sendings
  curl --location 'http://api.labsmobile.com/get/send.php?username=myUsername&password=myToken&msisdn=12015550123,12015550124,12015550125&message=Your%20verification%20code%20is%20123'
                
  #include <stdio.h> 
  #include <curl/curl.h> 

  int main(void)
  {
      CURL *curl;
      CURLcode res;
      char *username = "myUsername";
      char *token = "myToken";
      char *msisdn = "[12015550123,12015550124,12015550125]";
      char *message = "Don't miss our Sale! Use code XXXX123 for 20% off.";
      char *test = "1";

      char *encoded_username = curl_easy_escape(curl, username, 0);
      char *encoded_message = curl_easy_escape(curl, message, 0);
      char *encoded_msisdn = curl_easy_escape(curl, msisdn, 0);

      char url[500];
      sprintf(url, "http://api.labsmobile.com/get/send.php?username=%s&password=%s&msisdn=%s&message=%s&test=1", encoded_username, token, encoded_msisdn, encoded_message);

      curl = curl_easy_init();
      if (curl)
      {
          curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET");
          curl_easy_setopt(curl, CURLOPT_URL, url);
          curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
          curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
          res = curl_easy_perform(curl);
          if (res != CURLE_OK)
          {
              fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
          }
      }
      curl_free(encoded_username);
      curl_free(encoded_message);
      curl_free(encoded_msisdn);
      curl_easy_cleanup(curl);
      return 0;
  }
              
  using System;
  using RestSharp;

  namespace SendGetMul
  {
    class Program
    {
      static void MainSend(string[] args)
      {
        string username = "myUsername";
        string token = "myToken";
        string msisdn = "[12015550123,12015550124,12015550125]";
        string message = "Don't miss our Sale! Use code XXXX123 for 20% off.";

        var client = new RestClient("https://api.labsmobile.com");
        var request = new RestRequest("/get/send.php", Method.Get);

        request.AddParameter("username", username);
        request.AddParameter("password", token);
        request.AddParameter("msisdn", msisdn);
        request.AddParameter("message", message);

        RestResponse response = client.Execute(request);
        if (response.ErrorException != null)
        {
          Console.WriteLine("Error: " + response.ErrorException.Message);
        }
        else
        {
          Console.WriteLine("Response content: " + response.Content);
        }
      }
    }
  }
              
  import com.mashape.unirest.http.HttpResponse;
  import com.mashape.unirest.http.Unirest;
  import com.mashape.unirest.http.exceptions.UnirestException;

  import java.io.UnsupportedEncodingException;
  import java.net.URLEncoder;

  public class App {
    public static void main(String[] args) throws UnirestException, UnsupportedEncodingException {
        String username = "myUsername";
        String token = "myToken";
        String message = "Don't miss our Sale! Use code XXXX123 for 20% off.";
        String[] msisdn = {"12015550123,12015550124,12015550125"};

        String url = "http://api.labsmobile.com/get/send.php?username=" +
              URLEncoder.encode(username, "utf-8") +
              "&password=" + URLEncoder.encode(token, "utf-8") +
              "&message=" + URLEncoder.encode(message, "utf-8") +
              "&msisdn=" + URLEncoder.encode(String.join(",", msisdn), "utf-8");

        Unirest.setTimeouts(0, 0);
        HttpResponse<String> response = Unirest.get(url).asString();
        System.out.println("Status code: " + response.getBody());
    }
  }
              
<?php 
  $curl = curl_init();

  $username = "myUsername";
  $token = "myToken";
  $msisdn = array(12015550123,12015550124,12015550125);
  $message = "Don't miss our Sale! Use code XXXX123 for 20% off.";

  $url = 'http://api.labsmobile.com/get/send.php?';
              $url .= 'username='.  urlencode($username) .'&';
              $url .= 'password='.  urlencode($token) .'&';
              $url .= 'msisdn=' .  urlencode(json_encode($msisdn)) .'&';
              $url .= 'message=' .  urlencode($message);
  curl_setopt_array($curl, array(
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => '',
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 0,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => 'GET',
  ));

  $response = curl_exec($curl);

  curl_close($curl);
  echo $response;
              
  import requests, urllib.parse

  data = {
      'username':'myUsername',
      'password': 'myToken',
      'msisdn': '[12015550123,12015550124,12015550125]',
      'message':"Don't miss our Sale! Use code XXXX123 for 20% off."
      
  }
  url = "http://api.labsmobile.com/get/send.php?"+urllib.parse.urlencode(data, doseq=True)
  payload = {}
  headers = {}

  response = requests.request("GET", url, headers=headers, data=payload)

  print(response.text)
              
  const axios = require('axios');

  const username = "myUsername";
  const token = "myToken";
  const message = "Don't miss our Sale! Use code XXXX123 for 20% off.";
  const msisdns = ["12015550123","12015550124","12015550125"];

  let config = {
    method: 'get',
    maxBodyLength: Infinity,
    url: `http://api.labsmobile.com/get/send.php?username=${encodeURIComponent(username)}&password=${encodeURIComponent(token)}&message=${encodeURIComponent(message)}&msisdn=${encodeURIComponent(JSON.stringify(msisdns))}`
  };

  axios.request(config)
  .then((response) => {
    console.log(JSON.stringify(response.data));
  })
  .catch((error) => {
    console.log(error);
  });
              
  require "uri"
  require "net/http"

  url = URI("http://api.labsmobile.com/get/send.php")

  data = {
    'username' => 'myUsername',
    'password' => 'myToken',
    'msisdn': '[12015550123,12015550124,12015550125]',
    'message' => "Don't miss our Sale! Use code XXXX123 for 20% off."
  }

  url.query = URI.encode_www_form(data)
  https = Net::HTTP.new(url.host, url.port)
  request = Net::HTTP::Get.new(url)

  response = https.request(request)
  puts response.read_body
              
Positive result
  <?xml version="1.0" encoding="utf-8"?>
  <response>
        <code>0</code>
        <message>Message has been successfully sent</message>
        <subid>56fb9baa6bc22</subid>
  </response>
                  
Wrong result
  <?xml version="1.0" encoding="utf-8"?>
  <response>
      <subid>6615686480e47</subid>
      <code>21</code>
      <message>The message element cannot be empty</message>
  </response>
                  

Balance inquiry

Consult on the number of available credits of an account.

ENDPOINT

GET https://api.labsmobile.com/balance

  • PARAMETERS

  • RESULT

    The result of any SMS http/GET API request is obtained in XML format with the root element <response> and the following child element:

Balance inquiry
  curl --location 'http://api.labsmobile.com/get/balance.php?username=myUsername&password=myToken'
                
  #include <stdio.h> 
  #include <curl/curl.h> 

  int main(void)
  {
      CURL *curl;
      CURLcode res;

      char *username = "oscar.santa@labsmobile.com";
      char *token = "HWzeyIS8AX1jPio7P5ZNxpPDktQ1Lnpj";

      char *encoded_username = curl_easy_escape(curl, username, 0);

      char url[500]; 
      sprintf(url, "http://api.labsmobile.com/get/balance.php?username=%s&password=%s", encoded_username, token);

      curl = curl_easy_init();
      if (curl)
      {
          curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET");
          curl_easy_setopt(curl, CURLOPT_URL, url);
          curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
          curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
          res = curl_easy_perform(curl);
          if (res != CURLE_OK)
          {
              fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
          }
      }
      curl_free(encoded_username);
      curl_easy_cleanup(curl);
      return 0;
  }


              
  using System;
  using RestSharp;

  namespace BalanceGet
  {
    class Program
    {
      static void MainBalance(string[] args)
      {
        string username = "myUsername";
        string token = "myToken";

        var client = new RestClient("https://api.labsmobile.com");
        var request = new RestRequest("/get/balance.php", Method.Get);

        request.AddParameter("username", username);
        request.AddParameter("password", token);

        RestResponse response = client.Execute(request);
        if (response.ErrorException != null)
        {
          Console.WriteLine("Error: " + response.ErrorException.Message);
        }
        else
        {
          Console.WriteLine("Response content: " + response.Content);
        }
      }
    }
  }  
              
  import com.mashape.unirest.http.HttpResponse;
  import com.mashape.unirest.http.Unirest;
  import com.mashape.unirest.http.exceptions.UnirestException;

  import java.io.UnsupportedEncodingException;
  import java.net.URLEncoder;

  public class App {
      public static void main(String[] args) throws UnirestException, UnsupportedEncodingException {
          String username = "oscar.santa@labsmobile.com";
          String token = "HWzeyIS8AX1jPio7P5ZNxpPDktQ1Lnpj";

          String url = "http://api.labsmobile.com/get/balance.php?username=" +
                  URLEncoder.encode(username, "utf-8") +
                  "&password=" + URLEncoder.encode(token, "utf-8");

          Unirest.setTimeouts(0, 0);
          HttpResponse<String> response = Unirest.get(url).asString();
          System.out.println("Status code: " + response.getBody());
      }
  }
              
<?php 
  $curl = curl_init();

  $username = "myUsername";
  $token = "myToken";

  $url = 'http://api.labsmobile.com/get/balance.php?';
              $url .= 'username='.  urlencode($username) .'&';
              $url .= 'password='.  urlencode($token);
  curl_setopt_array($curl, array(
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => '',
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 0,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => 'GET',
  ));

  $response = curl_exec($curl);

  curl_close($curl);
  echo $response;

              
  import requests, urllib.parse

  data = {
      'username':'myUsername',
      'password': 'myToken'
  }


  url = "http://api.labsmobile.com/get/balance.php?"+urllib.parse.urlencode(data, doseq=True)
  print(url)
  payload = {}
  headers = {}

  response = requests.request("GET", url, headers=headers, data=payload)

  print(response.text)
              
  const axios = require('axios');

  const username = "myUsername";
  const token = "myToken";

  let config = {
    method: 'get',
    maxBodyLength: Infinity,
    url: `http://api.labsmobile.com/get/balance.php?username=${encodeURIComponent(username)}&password=${encodeURIComponent(token)}`
  };

  axios.request(config)
  .then((response) => {
    console.log(JSON.stringify(response.data));
  })
  .catch((error) => {
    console.log(error);
  });
              
  require "uri"
  require "net/http"

  url = URI("http://api.labsmobile.com/get/balance.php")

  data = {
    'username' => 'myUsername',
    'password' => 'myToken'
  }

  url.query = URI.encode_www_form(data)
  https = Net::HTTP.new(url.host, url.port)
  request = Net::HTTP::Get.new(url)

  response = https.request(request)
  puts response.read_body

              
Positive result
  <?xml version="1.0" encoding="utf-8"?>
  <response>
      <messages>9.956954285714286</messages>
  </response>
                  
Wrong result
  <html>
    <head>
      <title>403 Forbidden</title>
    </head>
    <body>
      <h1>403 Forbidden</h1>
    /body>
  </html>
                  

Errors

The HTTP error codes that may be returned by a request to the SMS http/GET API are described below.

HTTP codes
HTTP CodeDescription
200 OKRequest processed correctly.
400 Bad RequestError in the request parameters. The error is detailed and specified in the code returned in XML format.
401 UnauthorizedError in credentials or authentication method.
402 Payment RequiredError due to lack of credits in the account.
403 ForbiddenRequest blocked by the IP filter or for violating any platform usage policy.
500 Internal Server ErrorTemporary error or incidence in the service

This is the complete list of response codes in XML format:

Result codes in the response XML
XML CodeDescription
0Message has been successfully sent
10Missing XML data in request
11Badly formed XML in request
20The message element must be present in the request
21The message element cannot be empty
23There are no recipients
24Too many recipients
27This message contained one or more invalid character(s)
28Subid is exceeding maximum length
30There was an error while sending the message
35The account has no enough credit for this sending
39The value of the scheduled field is not a valid datetime format
41Scheduled messages cannot be send in test mode