ES

API for sending SMS http/POST

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

The functionalities of the SMS http/POST API are:

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

To start an integration with the http/POST 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/POST API endpoint and the parameter values to make the request.

To be taken into account

The LabsMobile http/POST API is a REST API that uses the HTTP POST protocol, the JSON format for information exchange and a common base URL for all requests: https://api.labsmobile.com/json/.

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


Authentication

The authentication method used is Auth Basic 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=

Recommendation You can generate API tokens from the API Settings of the account. We recommend changing the token frequently and using different tokens for each use, connection or integration.


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

POST https://api.labsmobile.com/json/send

  • Expand all

    PARAMETERS

    The parameters or data are sent in the body of an http/POST call in JSON format. The values and functionality of all parameters are described below.

    Example JSON format
    {
    "message":"Message text",
    "tpoa":"Sender",
    "recipient":
      [
        {"msisdn":"12015550123"},
        {"msisdn":"12015550124"},
        {"msisdn":"12015550125"},
      ],
    "test":"1",
    "subid":"L-203",
    "label":"from]=websms;[user]=admin[campaign]=salesJanuary"
    }
                          
  • RESULT

    The result is obtained in JSON format with the following elements:

Example code

Sending a standard message to a single recipient:

Individual sending
curl --user myUsername:myToken -X POST \
  https://api.labsmobile.com/json/send \
  -H 'Cache-Control: no-cache' \
  -H 'Content-Type: application/json' \
  -d '{"message":"Your verification code is 123", "tpoa":"Sender","recipient":[{"msisdn":"12015550123"}]}'
              
#include <stdio.h> 
#include <curl/curl.h> 

int main(void) {
    CURL *curl;
    CURLcode res;
    curl = curl_easy_init();
    if(curl) {
        curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
        curl_easy_setopt(curl, CURLOPT_URL, "https://api.labsmobile.com/json/send");
        curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
        curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
        curl_easy_setopt(curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_BASIC);
        curl_easy_setopt(curl, CURLOPT_USERNAME, "myUsername");
        curl_easy_setopt(curl, CURLOPT_PASSWORD, "myToken");
        struct curl_slist *headers = NULL;
        headers = curl_slist_append(headers, "Cache-Control: no-cache");
        headers = curl_slist_append(headers, "Content-Type: application/json");
        curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
        const char *data = "{\r\n  \"message\":\"Your verification code is 123\",\r\n  \"tpoa\":\"Sender\",\r\n  \"recipient\":\r\n    [\r\n      {\r\n        \"msisdn\":\"12015550123\"\r\n      }\r\n    ]\r\n}\r\n\r\n";
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
        res = curl_easy_perform(curl);
        if(res != CURLE_OK)
            fprintf(stderr, "curl_easy_perform() failed: %s\n",
                      curl_easy_strerror(res));
        curl_easy_cleanup(curl);
    }
    return 0;
}

            
using System;
using RestSharp;

namespace SendPostUni
{
  class Program
  {
    static void MainSend(string[] args)
    {
      var client = new RestClient("https://api.labsmobile.com");
      var request = new RestRequest("/json/send", Method.Post);
      request.AddHeader("Cache-Control", "no-cache");
      request.AddHeader("Content-Type", "application/json");
      request.AddHeader("Authorization", "Basic " + Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("myUsername" + ":" + "myToken")));
      request.AddParameter("application/json", "{\r\n  \"message\":\"Your verification code is 123\",\r\n  \"tpoa\":\"Sender\",\r\n  \"recipient\":\r\n    [\r\n      {\r\n        \"msisdn\":\"12015550123\"\r\n      }\r\n    ]\r\n}\r\n\r\n", ParameterType.RequestBody);
      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;

public class App {
  public static void main(String[] args) throws UnirestException {
    Unirest.setTimeouts(0, 0);
    HttpResponse<String> response = Unirest.post("https://api.labsmobile.com/json/send")
        .header("Content-Type", "application/json")
        .basicAuth("myUsername", "myToken")
        .header("Cache-Control", "no-cache")
        .body(
          "{\"message\":\"Your verification code is 123\", \"tpoa\":\"Sender\",\"recipient\":[{\"msisdn\":\"12015550123\"}]}")
        .asString();
    System.out.println("Status code: " + response.getBody());
  }
}
            
<?php 
$auth_basic = base64_encode("myUsername:myToken");

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.labsmobile.com/json/send",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => '{
    "message":"Your verification code is 123",
    "tpoa":"Sender",
    "recipient":
      [
        {
          "msisdn":"12015550123"
        }
      ]
  }',
  CURLOPT_HTTPHEADER => array(
    "Authorization: Basic ".$auth_basic,
    "Cache-Control: no-cache",
    "Content-Type: application/json"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
            
import requests, base64, json


userToken = "myUsername:myToken"
credentials = (base64.b64encode(userToken.encode()).decode())

url = "https://api.labsmobile.com/json/send"

payload = json.dumps({
  "message": "Your verification code is 123",
  "tpoa": "Sender",
  "recipient": [
    {
      "msisdn": "12015550123"
    }
  ]
})
headers = {
  'Content-Type': 'application/json',
  'Authorization': 'Basic %s' % credentials,
  'Cache-Control': "no-cache"
}

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

print(response.text)

            
const axios = require('axios');

const data = JSON.stringify({
  "message": "Your verification code is 123",
  "tpoa": "Sender",
  "recipient": [
    {
      "msisdn": "12015550123"
    }
  ]
});

let config = {
  method: 'post',
  maxBodyLength: Infinity,
  url: 'https://api.labsmobile.com/json/send',
  headers: { 
    'Content-Type': 'application/json', 
    'Authorization': 'Basic ' + Buffer.from("myUsername:myToken").toString('base64')
  },
  data : data
};

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



            
require "uri"
require "json"
require 'base64'
require "net/http"

url = URI("https://api.labsmobile.com/json/send")

https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Content-Type"] = "application/json"
request["Authorization"] = "Basic " + Base64.strict_encode64("myUsername:myToken")
request.body = JSON.dump({
  "message": "Your verification code is 123",
  "tpoa": "Sender",
  "recipient": [
    {
      "msisdn": "12015550123"
    }
  ]
})

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

            
Multiple sending
curl --user myUsername:myToken -X POST \
  https://api.labsmobile.com/json/send \
  -H 'Cache-Control: no-cache' \
  -H 'Content-Type: application/json' \
  -d '{"message":"Do not miss our Sale! Use code XXXX123 for 20% off.", "tpoa":"Sender","recipient":[{"msisdn":"12015550123"},{"msisdn":"12015550124"},{"msisdn":"12015550125"}]}'
              
#include <stdio.h> 
#include <curl/curl.h> 

int main(void) {
    CURL *curl;
    CURLcode res;
curl = curl_easy_init();
if(curl) {
  curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
  curl_easy_setopt(curl, CURLOPT_URL, "https://api.labsmobile.com/json/send");
  curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
  curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
  curl_easy_setopt(curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_BASIC);
  curl_easy_setopt(curl, CURLOPT_USERNAME, "myUsername");
  curl_easy_setopt(curl, CURLOPT_PASSWORD, "myToken");
  struct curl_slist *headers = NULL;
  headers = curl_slist_append(headers, "Cache-Control: no-cache");
  headers = curl_slist_append(headers, "Content-Type: application/json");
  curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
  const char *data = "{\r\n  \"message\":\"Do not miss our Sale! Use code XXXX123 for 20% off.\",\r\n  \"tpoa\":\"Sender\",\r\n  \"recipient\":\r\n    [\r\n      {\r\n        \"msisdn\":\"12015550123\"\r\n      },\r\n      {\r\n        \"msisdn\":\"12015550124\"\r\n      },\r\n      {\r\n        \"msisdn\":\"12015550125\"\r\n      }\r\n    ]\r\n}\r\n\r\n";
  curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
  res = curl_easy_perform(curl);
  if(res != CURLE_OK)
    fprintf(stderr, "curl_easy_perform() failed: %s\n",
       curl_easy_strerror(res));
    curl_easy_cleanup(curl);
   }
  return 0;
}

            
using System;
using RestSharp;

namespace SendPostMul
{
  class Program
  {
    static void MainSend(string[] args)
    {
      var client = new RestClient("https://api.labsmobile.com");
      var request = new RestRequest("/json/send", Method.Post);
      request.AddHeader("Cache-Control", "no-cache");
      request.AddHeader("Content-Type", "application/json");
      request.AddHeader("Authorization", "Basic " + Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("myUsername" + ":" + "myToken")));
      request.AddParameter("application/json", "{\r\n  \"message\":\"Don't miss our Sale! Use code XXXX123 for 20% off.\",\r\n  \"tpoa\":\"Sender\",\r\n  \"recipient\":\r\n    [\r\n      {\r\n        \"msisdn\":\"12015550123\"\r\n      },\r\n      {\r\n        \"msisdn\":\"12015550124\"\r\n      },\r\n      {\r\n        \"msisdn\":\"12015550125\"\r\n      }\r\n    ]\r\n}\r\n\r\n", ParameterType.RequestBody);
      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;

public class App {
  public static void main(String[] args) throws UnirestException {
    Unirest.setTimeouts(0, 0);
    HttpResponse<String> response = Unirest.post("https://api.labsmobile.com/json/send")
        .header("Content-Type", "application/json")
        .basicAuth("myUsername", "myToken")
        .header("Cache-Control", "no-cache")
        .body(
          "{\"message\":\"Don't miss our Sale! Use code XXXX123 for 20% off.\", \"tpoa\":\"Sender\",\"recipient\":[{\"msisdn\":\"12015550123\"},{\"msisdn\":\"12015550124\"},{\"msisdn\":\"12015550125\"}]}")
        .asString();
    System.out.println("Status code: " + response.getBody());
  }
}

            
<?php 
$auth_basic = base64_encode("myUsername:myToken");

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.labsmobile.com/json/send",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => '{
    "message":"Do not miss our Sale! Use code XXXX123 for 20% off.",
    "tpoa":"Sender",
    "recipient":
      [
        {
          "msisdn":"12015550123"
        },
        {
          "msisdn":"12015550124"
        },
        {
          "msisdn":"12015550125"
        }
      ]
  }',
  CURLOPT_HTTPHEADER => array(
    "Authorization: Basic ".$auth_basic,
    "Cache-Control: no-cache",
    "Content-Type: application/json"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
            
import requests, base64, json


userToken = "myUsername:myToken"
credentials = (base64.b64encode(userToken.encode()).decode())

url = "https://api.labsmobile.com/json/send"

payload = json.dumps({
  "message": "Don't miss our Sale! Use code XXXX123 for 20% off.",
  "tpoa": "Sender",
  "recipient": [
    {
      "msisdn": "12015550123"
    },
    {
      "msisdn": "12015550124"
    },
    {
      "msisdn": "12015550125"
    }
  ]
})
headers = {
  'Content-Type': 'application/json',
  'Authorization': 'Basic %s' % credentials,
  'Cache-Control': "no-cache"
}

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

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

const data = JSON.stringify({
    "message": "Don't miss our Sale! Use code XXXX123 for 20% off.",
    "tpoa": "Sender",
    "recipient": [
      {
        "msisdn": "12015550123"
      },
      {
        "msisdn": "12015550124"
      },
      {
        "msisdn": "12015550125"
      }
    ]
})

let config = {
  method: 'post',
  maxBodyLength: Infinity,
  url: 'https://api.labsmobile.com/json/send',
  headers: { 
    'Content-Type': 'application/json', 
    'Authorization': 'Basic ' + Buffer.from("myUsername:myToken").toString('base64')
  },
  data : data
};

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

            
require "uri"
require "json"
require 'base64'
require "net/http"

url = URI("https://api.labsmobile.com/json/send")

https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Content-Type"] = "application/json"
request["Authorization"] = "Basic " + Base64.strict_encode64("myUsername:myToken")
request.body = JSON.dump({
  "message": "Don't miss our Sale! Use code XXXX123 for 20% off.",
  "tpoa": "Sender",
  "recipient": [
    {
      "msisdn": "12015550123"
    },
    {
      "msisdn": "12015550124"
    },
    {
      "msisdn": "12015550125"
    }
  ]
})

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

            
Positive result
{
  "subid": "65f33a88ceb3d",
  "code": "0",
  "message": "Message has been successfully sent."
}
              
Wrong result
{
  "subid": "65f7f7041385d",
  "code": "35",
  "message": "The account has no enough credit for this sending"
}
              

Balance inquiry

Consult on the number of available credits of an account.

ENDPOINT

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

This functionality has no parameters, just send the correct credentials to identify the account to the balance inquiry endpoint.

  • RESULT

    The result of any SMS http/POST API request is obtained in JSON format with the following elements:

Balance inquiry
curl --user myUsername:myToken -X GET \
  https://api.labsmobile.com/json/balance \
  -H 'Cache-Control: no-cache' \              
#include <stdio.h> 
#include <curl/curl.h> 

int main(void) {
    CURL *curl;
    CURLcode res;
    curl = curl_easy_init();
    if(curl) {
        curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET");
        curl_easy_setopt(curl, CURLOPT_URL, "https://api.labsmobile.com/json/balance");
        curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
        curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
        curl_easy_setopt(curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_BASIC);
        curl_easy_setopt(curl, CURLOPT_USERNAME, "myUsername");
        curl_easy_setopt(curl, CURLOPT_PASSWORD, "myToken");
        struct curl_slist *headers = NULL;
        curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
        const char *data = "";
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
        res = curl_easy_perform(curl);
        if(res != CURLE_OK)
            fprintf(stderr, "curl_easy_perform() failed: %s\n",
                      curl_easy_strerror(res));
        curl_easy_cleanup(curl);
    }
    return 0;
}
            
using System;
using RestSharp;

namespace BalancePost
{
  class Program
  {
    static void MainBalance(string[] args)
    {
      var client = new RestClient("https://api.labsmobile.com");
      var request = new RestRequest("/json/balance", Method.Get);
      request.AddHeader("Cache-Control", "no-cache");
      request.AddHeader("Content-Type", "application/json");
      request.AddHeader("Authorization", "Basic " + Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("myUsername" + ":" + "myToken")));
      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;

public class App {
  public static void main(String[] args) throws UnirestException {
    Unirest.setTimeouts(0, 0);
    HttpResponse<String> response = Unirest.get("https://api.labsmobile.com/json/balance")
        .header("Content-Type", "application/json")
        .basicAuth("myUsername", "myToken")
        .header("Cache-Control", "no-cache")
        .body("")
        .asString();
    System.out.println("Status code: " + response.getBody());
  }
}

            
<?php 
$auth_basic = base64_encode("myUsername:myToken");

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.labsmobile.com/json/balance",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "Authorization: Basic ".$auth_basic,
    "Cache-Control: no-cache",
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}

            
import requests, base64, json

userToken = "myUsername:myToken"
credentials = (base64.b64encode(userToken.encode()).decode())

url = "https://api.labsmobile.com/json/balance"

payload = ""
headers = {
  'Content-Type': 'application/json',
  'Authorization': 'Basic %s' % credentials,
  'Cache-Control': "no-cache"
}

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

print(response.text)

            
const axios = require('axios');
let data = '';

let config = {
  method: 'get',
  maxBodyLength: Infinity,
  url: 'https://api.labsmobile.com/json/balance',
  headers: { 
    'Authorization': 'Basic ' + Buffer.from("myUsername:myToken").toString('base64')
  },
  data : data
};

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

            
require "uri"
require "json"
require 'base64'
require "net/http"

url = URI("https://api.labsmobile.com/json/balance")

https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true

request = Net::HTTP::Get.new(url)
request["Content-Type"] = "application/json"
request["Authorization"] = "Basic " + Base64.strict_encode64("myUsername:myToken")
request.body = ""

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


            
Positive result
{
  "code":0,
  "credits":"10"
}
              
Wrong result
{
  "code":"403",
  "message":"Forbidden"
}
              

Price inquiry

Consult on the tariff (in credits) for one or more destination countries.

ENDPOINT

GET https://api.labsmobile.com/json/prices

  • PARAMETERS

    The parameters or data are sent in the body of an http/POST call in JSON format. The values and functionality of all parameters are described below.

  • Expand all

    RESULT

    The result is obtained in JSON, XML or CSV format with the following elements:

Price inquiry
curl --user myusername:mypassword -X POST \
  https://api.labsmobile.com/json/prices \
  -H 'Cache-Control: no-cache' \
  -H 'Content-Type: application/json' \
  -d '{"format":"JSON","countries":["ES","FR","US","MX"]}'          
#include <stdio.h> 
#include <curl/curl.h> 

int main(void) {
    CURL *curl;
    CURLcode res;
    curl = curl_easy_init();
    if(curl) {
        curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
        curl_easy_setopt(curl, CURLOPT_URL, "https://api.labsmobile.com/json/prices");
        curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
        curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
        curl_easy_setopt(curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_BASIC);
        curl_easy_setopt(curl, CURLOPT_USERNAME, "myUsername");
        curl_easy_setopt(curl, CURLOPT_PASSWORD, "myToken");
        struct curl_slist *headers = NULL;
        headers = curl_slist_append(headers, "Cache-Control: no-cache");
        headers = curl_slist_append(headers, "Content-Type: application/json");
        curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
        const char *data = "{\"format\":\"JSON\",\"countries\":[\"ES\",\"FR\",\"US\",\"MX\"]}";
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
        res = curl_easy_perform(curl);
        if(res != CURLE_OK)
            fprintf(stderr, "curl_easy_perform() failed: %s\n",
                      curl_easy_strerror(res));
        curl_easy_cleanup(curl);
    }
    return 0;
}

            
using System;
using RestSharp;

namespace Prices
{
  class Program
  {
    static void MainPrices(string[] args)
    {
      var client = new RestClient("https://api.labsmobile.com");
      var request = new RestRequest("/json/prices", Method.Post);
      request.AddHeader("Cache-Control", "no-cache");
      request.AddHeader("Content-Type", "application/json");
      request.AddHeader("Authorization", "Basic " + Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("myUsername" + ":" + "myToken")));
      request.AddParameter("application/json", "{\"format\":\"JSON\",\"countries\":[\"ES\",\"FR\",\"US\",\"MX\"]}", ParameterType.RequestBody);
      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;

public class App {
  public static void main(String[] args) throws UnirestException {
    Unirest.setTimeouts(0, 0);
    HttpResponse<String> response = Unirest.post("https://api.labsmobile.com/json/prices")
        .header("Content-Type", "application/json")
        .basicAuth("myUsername", "myToken")
        .header("Cache-Control", "no-cache")
        .body(
          "{\"format\":\"JSON\",\"countries\":[\"ES\",\"FR\",\"US\",\"MX\"]}")
        .asString();
    System.out.println("Status code: " + response.getBody());
  }
}
            
<?php 
$auth_basic = base64_encode("myUsername:myToken");

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.labsmobile.com/json/prices",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => '{
    "format":"JSON",
    "countries":["ES","FR","US","MX"]
  }',
  CURLOPT_HTTPHEADER => array(
    "Authorization: Basic ".$auth_basic,
    "Cache-Control: no-cache",
    "Content-Type: application/json"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
            
import requests, base64, json

userToken = "myUsername:myToken"
credentials = (base64.b64encode(userToken.encode()).decode())

url = "https://api.labsmobile.com/json/prices"

payload = json.dumps({
    "format":"JSON",
    "countries":["ES","FR","US","MX"]
})
headers = {
  'Content-Type': 'application/json',
  'Authorization': 'Basic %s' % credentials,
  'Cache-Control': "no-cache"
}

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

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

const data = JSON.stringify({
  "format":"JSON",
  "countries":["ES","FR","US","MX"]
});

let config = {
  method: 'post',
  maxBodyLength: Infinity,
  url: 'https://api.labsmobile.com/json/prices',
  headers: { 
    'Content-Type': 'application/json', 
    'Authorization': 'Basic ' + Buffer.from("myUsername:myToken").toString('base64')
  },
  data : data
};

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

            
require "uri"
require "json"
require 'base64'
require "net/http"

url = URI("https://api.labsmobile.com/json/prices")

https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Content-Type"] = "application/json"
request["Authorization"] = "Basic " + Base64.strict_encode64("myUsername:myToken")
request.body = JSON.dump({
  "format":"JSON",
  "countries":["ES","FR","US","MX"]
})

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

            
Positive result
{
  "FR":
    {
      "isocode":"FR",
      "prefix":"33",
      "name":"France",
      "credits":1.114
    },
  "DE":
    {
      "isocode":"DE",
      "prefix":"49",
      "name":"Germany",
      "credits":1.8
    }
}
              
Wrong result
{
    "code": "401",
    "message": "Unauthorized"
}
              

Managing scheduled sendings

Cancellation or execution of pending scheduled sengings.

ENDPOINT

POST https://api.labsmobile.com/json/scheduled.

  • PARAMETERS

    The parameters or data are sent in the body of an http/POST call in JSON format. The values and functionality of all parameters are described below.

  • RESULT

    The result is obtained in JSON format with the following elements:

Cancel programmed
curl --user myusername:mypassword -X POST \
  https://api.labsmobile.com/json/scheduled \
  -H 'Cache-Control: no-cache' \
  -H 'Content-Type: application/json' \
  -d '{"cmd":"cancel","subid":"5a9fe45c7adc3"}'         
#include <stdio.h> 
#include <curl/curl.h> 

int main(void) {
    CURL *curl;
    CURLcode res;
    curl = curl_easy_init();
    if(curl) {
        curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
        curl_easy_setopt(curl, CURLOPT_URL, "https://api.labsmobile.com/json/scheduled");
        curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
        curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
        curl_easy_setopt(curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_BASIC);
        curl_easy_setopt(curl, CURLOPT_USERNAME, "myUsername");
        curl_easy_setopt(curl, CURLOPT_PASSWORD, "myToken");
        struct curl_slist *headers = NULL;
        headers = curl_slist_append(headers, "Cache-Control: no-cache");
        headers = curl_slist_append(headers, "Content-Type: application/json");
        curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
        const char *data = "{\"cmd\":\"cancel\",\"subid\":\"5a9fe45c7adc3\"}";
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
        res = curl_easy_perform(curl);
        if(res != CURLE_OK)
            fprintf(stderr, "curl_easy_perform() failed: %s\n",
                      curl_easy_strerror(res));
        curl_easy_cleanup(curl);
    }
    return 0;
}

            
using System;
using RestSharp;

namespace Prices
{
  class Program
  {
    static void MainPrices(string[] args)
    {
      var client = new RestClient("https://api.labsmobile.com");
      var request = new RestRequest("/json/scheduled", Method.Post);
      request.AddHeader("Cache-Control", "no-cache");
      request.AddHeader("Content-Type", "application/json");
      request.AddHeader("Authorization", "Basic " + Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("myUsername" + ":" + "myToken")));
      request.AddParameter("application/json", "{\"cmd\":\"cancel\",\"subid\":\"5a9fe45c7adc3\"}", ParameterType.RequestBody);
      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;

public class App {
  public static void main(String[] args) throws UnirestException {
    Unirest.setTimeouts(0, 0);
    HttpResponse<String> response = Unirest.post("https://api.labsmobile.com/json/scheduled")
        .header("Content-Type", "application/json")
        .basicAuth("myUsername", "myToken")
        .header("Cache-Control", "no-cache")
        .body(
          "{\"cmd\":\"cancel\",\"subid\":\"5a9fe45c7adc3\"}")
        .asString();
    System.out.println("Status code: " + response.getBody());
  }
}
            
<?php 
$auth_basic = base64_encode("myUsername:myToken");

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.labsmobile.com/json/scheduled",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => '{
    "cmd":"cancel",
    "subid":"5a9fe45c7adc3"
  }',
  CURLOPT_HTTPHEADER => array(
    "Authorization: Basic ".$auth_basic,
    "Cache-Control: no-cache",
    "Content-Type: application/json"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
            
import requests, base64, json

userToken = "myUsername:myToken"
credentials = (base64.b64encode(userToken.encode()).decode())

url = "https://api.labsmobile.com/json/scheduled"

payload = json.dumps({
  "cmd":"cancel",
  "subid":"5a9fe45c7adc3"
})
headers = {
  'Content-Type': 'application/json',
  'Authorization': 'Basic %s' % credentials,
  'Cache-Control': "no-cache"
}

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

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

const data = JSON.stringify({
  "cmd":"cancel",
  "subid":"5a9fe45c7adc3"
});

let config = {
  method: 'post',
  maxBodyLength: Infinity,
  url: 'https://api.labsmobile.com/json/scheduled',
  headers: { 
    'Content-Type': 'application/json', 
    'Authorization': 'Basic ' + Buffer.from("myUsername:myToken").toString('base64')
  },
  data : data
};

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

            
require "uri"
require "json"
require 'base64'
require "net/http"

url = URI("https://api.labsmobile.com/json/scheduled")

https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Content-Type"] = "application/json"
request["Authorization"] = "Basic " + Base64.strict_encode64("myUsername:myToken")
request.body = JSON.dump({
  "cmd":"cancel",
  "subid":"5a9fe45c7adc3"
})

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

            
Positive result
{
  "code":"0",
  "message":"Scheduled messages successfully cancelled."
}
              
Wrong result
{
  "code":"52",
  "message":"Scheduled messages not found."
}
              

Receipt of statuses

Obtaining the status (delivered or error) of sent messages.

With this functionality, the client receives in a URL the delivery confirmation or error events of each message sent.

There are two methods to enable receiving statuses in a URL:

  • Adding a URL in the ackurl parameter of the sending API request.
  • By entering a URL in the Account API Settings, in the URL for receiving confirmations or delivery errors field.

In both cases when a message delivered or error status occurs, an http/GET call will be made to the URL provided with the parameters detailed below.

  • Expand all

    PARAMETERS

URL format: ?acklevel=[gateway|operator|handset|error]&msisdn=[phone]&status=[ok|ko&desc=[REJECTD|EXPIRED|BLOCKED|UNDELIV|UNKNOWN]&subid=[identifier]&timestamp=YYYYY-MM-DD%20HH:MM:SS.

RetriesIf the http/GET call generates an error when calling the URL (HTTP 4xx or 5xx states) the delivery will be reattempted up to 5 times at the following intervals: 30s, 5m, 30m, 6h, 1d.


Receiving clicks

Getting the clicks on the URLs of sent messages.

With this functionality, click events that occur in sent messages are received in a URL of the client.

There are two methods to enable receiving clicks on a URL:

  • Adding a URL in the clickurl parameter of the submit API request.
  • By entering a URL in the Configuration API of the account, in the URL for receiving visits or clicks field.

In both cases when a click on a URL occurs an http/POST JSON call will be made to the URL provided with the parameters detailed below.

  • Expand all

    PARAMETERS

JSON Example
{
  ip : "98.139.180.149",
  useragent : "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0",
  subid : "5aa3ea8e5cdb6",
  msisdn : "5212221234567",
  timestamp : "2018-03-18 15:23:10"
}
                

RetriesIf the http/GET call generates an error when calling the URL (HTTP 4xx or 5xx states) the delivery will be reattempted up to 5 times at the following intervals: 30s, 5m, 30m, 6h, 1d.

Important In order to receive clicks, SMS messages must be delivered with a domain associated with the LabsMobile platform (labsmo.bi or custom domain configured).


Message reception

Reception of SMS messages in the contracted virtual numbers.

With this functionality the received SMS messages are received in a URL of the client.

To enable receiving SMS messages on a URL you need to enter a URL in the Account API Settings, in the URL for receiving messages field.

When an SMS is received it will make an http/POST JSON call to the URL provided with the parameters listed below.

  • Expand all

    PARAMETERS

JSON Example
{
  "inbound_number":"12015576234",
  "service_number":"12015576234",
  "msisdn":"12015550123",
  "message":"Test message",
  "timestamp":"2014-06-07 19:21:43"
}
                

RetriesIf the http/GET call generates an error when calling the URL (HTTP 4xx or 5xx states) the delivery will be reattempted up to 5 times at the following intervals: 30s, 5m, 30m, 6h, 1d.

Important To receive SMS messages it is necessary to contract virtual numbers for sending and receiving SMS.


Errors

The HTTP error codes that may be returned by a request to the SMS http/POST 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 JSON 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 JSON format:

Result codes in the response JSON
JSON 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
51Compulsary fields not defined.
52Scheduled messages not found.