OTP API
The API OTP is designed for technicians and customers who want to send OTP codes through the SMS channel.
The OTP codes (One Time Password) are single-use codes used in 2fa (Two Factor Authentication) verification or authentication processes.
To start an integration with the OTP 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 OTP API endpoint and the parameter values for making requests.
To be taken into account
LabsMobile's API OTP uses HTTP GET parameters and a common base URL for all requests: https://api.labsmobile.com/otp/
.
It is also possible to send OTP code by SMS with our API http/POST choosing all aspects such as retries, validations, OTP format, etc.
Authentication
The authentication method used in any OTP API request is 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=
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.
Send OTP code
Creation of an OTP code for a given number and environment.
This request generates a new OTP code for a specified mobile number and environment. An SMS will be sent to the number with the text containing the OTP code.
OTP codes and validation processes are framed in an environment to identify the project, application or version to which it belongs.
Important Sending an OTP code will cancel all previous codes pending validation for this number and environment and a new code will be generated. In case you want to resend an OTP code for the same validation process you must use the Send OTP Code function.
ENDPOINT
GET https://api.labsmobile.com/otp/sendCode
- 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:
phone_number string mandatory
Cell phone number to which you want to send the OTP code. The numbers must comply with the international E.164 format, including the country code without "00" and "+".
Example:
&phone_number=167923402323
env string
Environment where this request is framed. It is possible to set an empty or null environment. The same number can be validated in several environments...
Example:
&env=VerifApp
.message string
Text of the SMS message that the recipient of the OTP code will receive. The text must contain the
%CODE%
variable that will be replaced by the OTP code. By default, the value of the message text is: The code to verify your phone number is %CODE%.Example:
&message=Your%20code%3A%20%25CODE%25
.sender string
SMS message sender field. It can have a numeric value (maximum length 16 digits) or an alphanumeric value (maximum length 11 characters).
Sender assignment and customization is only available in some countries and operators. Otherwise, the sender will be a static numeric value (shortcode or longcode). Default value: NumCheck.
Example:
&sender=MyBRAND
digits integer
Number of digits of the OTP code to be generated. Default value 6, minimum of 4 and maximum of 9.
Example:
&digits=4
.RESULT
The result is obtained in the body of the HTTP response and can contain the following values:
Status values0
Incorrect request or error in sending or processing the OTP code. 1
Request for creation and successful sending of OTP code.
curl --user myUsername:myToken -X GET \ https://api.labsmobile.com/otp/sendCode?env=verifApp&sender=MyBRAND&phone_number=12015550123&message=The+code+to+verify+your+username+is%25CODE%25
#include <stdio.h> #include <curl/curl.h> int main(void) { CURL *curl; CURLcode res; char *env = "verifApp"; char *sender = "MyBRAND"; char *phone_number = "12015550123"; char *message = "The code to verify your username is %CODE%"; curl = curl_easy_init(); if(curl) { char *encoded_env = curl_easy_escape(curl, env, 0); char *encoded_sender = curl_easy_escape(curl, sender, 0); char *encoded_phone_number = curl_easy_escape(curl, phone_number, 0); char *encoded_message = curl_easy_escape(curl, message, 0); char url[1024]; snprintf(url, sizeof(url), "https://api.labsmobile.com/otp/sendCode?env=%s&sender=%s&phone_number=%s&message=%s", encoded_env, encoded_sender, encoded_phone_number, encoded_message); curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET"); curl_easy_setopt(curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_BASIC); curl_easy_setopt(curl, CURLOPT_USERNAME, "myUsername"); curl_easy_setopt(curl, CURLOPT_PASSWORD, "myToken"); res = curl_easy_perform(curl); if(res != CURLE_OK) { fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); } curl_free(encoded_env); curl_free(encoded_sender); curl_free(encoded_phone_number); curl_free(encoded_message); curl_easy_cleanup(curl); } return 0; }
using System; using RestSharp; namespace SendOtp { class Program { static void MainSend(string[] args) { var client = new RestClient("https://api.labsmobile.com"); var request = new RestRequest("/otp/sendCode", Method.Get); request.AddQueryParameter("env", "verifApp"); request.AddQueryParameter("sender", "MyBRAND"); request.AddQueryParameter("phone_number", "12015550123"); request.AddQueryParameter("message", "The code to verify your username is %CODE%"); request.AddHeader("Cache-Control", "no-cache"); 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; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; public class App { public static void main(String[] args) throws UnirestException, UnsupportedEncodingException { String env = URLEncoder.encode("verifApp", "UTF-8"); String sender = URLEncoder.encode("MyBRAND", "UTF-8"); String phoneNumber = URLEncoder.encode("12015550123", "UTF-8"); String message = URLEncoder.encode("The code to verify your username is %CODE%", "UTF-8"); String url = String.format("https://api.labsmobile.com/otp/sendCode?env=%s&sender=%s&phone_number=%s&message=%s", env, sender, phoneNumber, message); Unirest.setTimeouts(0, 0); HttpResponse<String> response = Unirest.get(url) .basicAuth("myUsername", "myToken") .header("Cache-Control", "no-cache") .asString(); System.out.println("Response content: " + response.getBody()); } }
<?php $auth_basic = base64_encode("myUsrname:myToken"); $curl = curl_init(); $env = "verifApp"; $sender = "MyBRAND"; $phone_number = "12015550123"; $message = "The code to verify your username is %CODE%"; $url = 'https://api.labsmobile.com/otp/sendCode?'; $url .= 'env='. urlencode($env) .'&'; $url .= 'sender='. urlencode($sender) .'&'; $url .= 'phone_number=' . urlencode($phone_number) .'&'; $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', CURLOPT_HTTPHEADER => array( 'Authorization: Basic '.$auth_basic ), )); $response = curl_exec($curl); curl_close($curl); echo $response;
import requests, base64, urllib.parse userToken = "myUsername:myToken" credentials = (base64.b64encode(userToken.encode()).decode()) data = { 'env':'verifApp', 'sender': 'MyBRAND', 'phone_number': '12015550123', 'message':'The code to verify your username is %CODE%' } url = "https://api.labsmobile.com/otp/sendCode?"+urllib.parse.urlencode(data, doseq=True) payload = {} headers = { 'Authorization': 'Basic %s' % credentials, } response = requests.request("GET", url, headers=headers, data=payload) print(response.text)
const axios = require('axios'); const env = "verifApp"; const sender = "MyBRAND"; const phone_number = "12015550123"; const message = "The code to verify your username is %CODE%"; let config = { method: 'get', maxBodyLength: Infinity, url: `https://api.labsmobile.com/otp/sendCode?env=${encodeURIComponent(env)}&sender=${encodeURIComponent(sender)}&phone_number=${encodeURIComponent(phone_number)}&message=${encodeURIComponent(message)}`, headers: { 'Authorization': 'Basic ' + Buffer.from("myUsername:myToken").toString('base64') }, }; axios.request(config) .then((response) => { console.log(JSON.stringify(response.data)); }) .catch((error) => { console.log(error); });
require "uri" require 'base64' require "net/http" url = URI("https://api.labsmobile.com/otp/sendCode") data = { 'env' => 'verifApp', 'sender' => 'MyBRAND', 'phone_number' => '12015550123', 'message' => 'The code to verify your username is %CODE%' } url.query = URI.encode_www_form(data) https = Net::HTTP.new(url.host, url.port) https.use_ssl = true request = Net::HTTP::Get.new(url) request["Authorization"] = "Basic " + Base64.strict_encode64("myUsername:myToken") response = https.request(request) puts response.read_body
Resend OTP code
Sending an OTP code for a given number and environment.
It is important to call this function to always send the same OTP code for the same validation process.
Important If there is no code generated for the number and environment sent, a new OTP code will be created in the same way as the Send OTP Code function does.
ENDPOINT
GET https://api.labsmobile.com/otp/resendCode
- 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:
phone_number string mandatory
Cell phone number to which you want to send the OTP code. The numbers must comply with the international E.164 format, including the country code without "00" and "+".
Example:
&phone_number=167923402323
env string
Environment where this request is framed. It is possible to set an empty or null environment. The same number can be validated in several environments...
Example:
&env=VerifApp
.message string
Text of the SMS message that the recipient of the OTP code will receive. The text must contain the
%CODE%
variable that will be replaced by the OTP code. By default, the value of the message text is: The code to verify your phone number is %CODE%.Example:
&message=Your%20code%3A%20%25CODE%25
.sender string
SMS message sender field. It can have a numeric value (maximum length 16 digits) or an alphanumeric value (maximum length 11 characters).
Sender assignment and customization is only available in some countries and operators. Otherwise, the sender will be a static numeric value (shortcode or longcode). Default value: NumCheck.
Example:
&sender=MyBRAND
digits integer
Number of digits of the OTP code to be generated. Default value 6, minimum of 4 and maximum of 9.
Example:
&digits=4
.RESULT
The result is obtained in the body of the HTTP response and can contain the following values:
Status values0
Incorrect request or error in sending or processing the OTP code. 1
Request for creation and successful sending of OTP code.
curl --user myUsername:myToken -X GET \ https://api.labsmobile.com/otp/resendCode?env=verifApp&sender=MyBRAND&phone_number=12015550123&message=The+code+to+verify+your+username+is%25CODE%25
#include <stdio.h> #include <curl/curl.h> int main(void) { CURL *curl; CURLcode res; char *env = "verifApp"; char *sender = "MyBRAND"; char *phone_number = "12015550123"; char *message = "The code to verify your username is %CODE%"; curl = curl_easy_init(); if(curl) { char *encoded_env = curl_easy_escape(curl, env, 0); char *encoded_sender = curl_easy_escape(curl, sender, 0); char *encoded_phone_number = curl_easy_escape(curl, phone_number, 0); char *encoded_message = curl_easy_escape(curl, message, 0); char url[1024]; snprintf(url, sizeof(url), "https://api.labsmobile.com/otp/resendCode?env=%s&sender=%s&phone_number=%s&message=%s", encoded_env, encoded_sender, encoded_phone_number, encoded_message); curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET"); curl_easy_setopt(curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_BASIC); curl_easy_setopt(curl, CURLOPT_USERNAME, "myUsername"); curl_easy_setopt(curl, CURLOPT_PASSWORD, "myToken"); res = curl_easy_perform(curl); if(res != CURLE_OK) { fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); } curl_free(encoded_env); curl_free(encoded_sender); curl_free(encoded_phone_number); curl_free(encoded_message); curl_easy_cleanup(curl); } return 0; }
using System; using RestSharp; namespace SendOtp { class Program { static void MainSend(string[] args) { var client = new RestClient("https://api.labsmobile.com"); var request = new RestRequest("/otp/resendCode", Method.Get); request.AddQueryParameter("env", "verifApp"); request.AddQueryParameter("sender", "MyBRAND"); request.AddQueryParameter("phone_number", "12015550123"); request.AddQueryParameter("message", "The code to verify your username is %CODE%"); request.AddHeader("Cache-Control", "no-cache"); 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; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; public class App { public static void main(String[] args) throws UnirestException, UnsupportedEncodingException { String env = URLEncoder.encode("verifApp", "UTF-8"); String sender = URLEncoder.encode("MyBRAND", "UTF-8"); String phoneNumber = URLEncoder.encode("12015550123", "UTF-8"); String message = URLEncoder.encode("The code to verify your username is %CODE%", "UTF-8"); String url = String.format("https://api.labsmobile.com/otp/resendCode?env=%s&sender=%s&phone_number=%s&message=%s", env, sender, phoneNumber, message); Unirest.setTimeouts(0, 0); HttpResponse<String> response = Unirest.get(url) .basicAuth("myUsername", "myToken") .header("Cache-Control", "no-cache") .asString(); System.out.println("Response content: " + response.getBody()); } }
<?php $auth_basic = base64_encode("myUsrname:myToken"); $curl = curl_init(); $env = "verifApp"; $sender = "MyBRAND"; $phone_number = "12015550123"; $message = "The code to verify your username is %CODE%"; $url = 'https://api.labsmobile.com/otp/resendCode?'; $url .= 'env='. urlencode($env) .'&'; $url .= 'sender='. urlencode($sender) .'&'; $url .= 'phone_number=' . urlencode($phone_number) .'&'; $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', CURLOPT_HTTPHEADER => array( 'Authorization: Basic '.$auth_basic ), )); $response = curl_exec($curl); curl_close($curl); echo $response;
import requests, base64, urllib.parse userToken = "myUsername:myToken" credentials = (base64.b64encode(userToken.encode()).decode()) data = { 'env':'verifApp', 'sender': 'MyBRAND', 'phone_number': '12015550123', 'message':'The code to verify your username is %CODE%' } url = "https://api.labsmobile.com/otp/resendCode?"+urllib.parse.urlencode(data, doseq=True) payload = {} headers = { 'Authorization': 'Basic %s' % credentials, } response = requests.request("GET", url, headers=headers, data=payload) print(response.text)
const axios = require('axios'); const env = "verifApp"; const sender = "MyBRAND"; const phone_number = "12015550123"; const message = "The code to verify your username is %CODE%"; let config = { method: 'get', maxBodyLength: Infinity, url: `https://api.labsmobile.com/otp/resendCode?env=${encodeURIComponent(env)}&sender=${encodeURIComponent(sender)}&phone_number=${encodeURIComponent(phone_number)}&message=${encodeURIComponent(message)}`, headers: { 'Authorization': 'Basic ' + Buffer.from("myUsername:myToken").toString('base64') }, }; axios.request(config) .then((response) => { console.log(JSON.stringify(response.data)); }) .catch((error) => { console.log(error); });
require "uri" require 'base64' require "net/http" url = URI("https://api.labsmobile.com/otp/resendCode") data = { 'env' => 'verifApp', 'sender' => 'MyBRAND', 'phone_number' => '12015550123', 'message' => 'The code to verify your username is %CODE%' } url.query = URI.encode_www_form(data) https = Net::HTTP.new(url.host, url.port) https.use_ssl = true request = Net::HTTP::Get.new(url) request["Authorization"] = "Basic " + Base64.strict_encode64("myUsername:myToken") response = https.request(request) puts response.read_body
Validate OTP code
Validate the OTP code corresponding to a specific number and environment.
ENDPOINT
GET https://api.labsmobile.com/otp/validateCode
PARAMETERS
phone_number string mandatory
Telephone number to be validated.
Example:
&phone_number=167923402323
env string
Environment where this petition is framed.
Example:
&env=VerifApp
.code string
The code entered by the user and to be validated.
Example:
&code=652871
.RESULT
The result is obtained in the body of the HTTP response and can contain the following values:
Status values0
Nonexistent or incorrect OTP code for this number. 1
Correct and validated OTP code.
curl --user myUsername:myToken -X GET \ https://api.labsmobile.com/otp/validateCode?env=verifApp&phone_number=12015550123&code=381102
#include <stdio.h> #include <curl/curl.h> int main(void) { CURL *curl; CURLcode res; char *env = "verifApp"; char *phone_number = "12015550123"; char *code = "652871"; curl = curl_easy_init(); if(curl) { char *encoded_env = curl_easy_escape(curl, env, 0); char *encoded_phone_number = curl_easy_escape(curl, phone_number, 0); char *encoded_code = curl_easy_escape(curl, code, 0); char url[1024]; snprintf(url, sizeof(url), "https://api.labsmobile.com/otp/validateCode?env=%s&phone_number=%s&code=%s", encoded_env, encoded_phone_number, encoded_code); curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET"); curl_easy_setopt(curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_BASIC); curl_easy_setopt(curl, CURLOPT_USERNAME, "myUsername"); curl_easy_setopt(curl, CURLOPT_PASSWORD, "myToken"); res = curl_easy_perform(curl); if(res != CURLE_OK) { fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); } curl_free(encoded_env); curl_free(encoded_phone_number); curl_easy_cleanup(curl); } return 0; }
using System; using RestSharp; namespace SendOtp { class Program { static void MainSend(string[] args) { var client = new RestClient("https://api.labsmobile.com"); var request = new RestRequest("/otp/validateCode", Method.Get); request.AddQueryParameter("env", "verifApp"); request.AddQueryParameter("phone_number", "12015550123"); request.AddQueryParameter("code", "652871"); request.AddHeader("Cache-Control", "no-cache"); 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; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; public class App { public static void main(String[] args) throws UnirestException, UnsupportedEncodingException { String env = URLEncoder.encode("verifApp", "UTF-8"); String phoneNumber = URLEncoder.encode("12015550123", "UTF-8"); String code = URLEncoder.encode("652871", "UTF-8"); String url = String.format("https://api.labsmobile.com/otp/validateCode?env=%s&phone_number=%s&code=%s", env, phoneNumber, code); Unirest.setTimeouts(0, 0); HttpResponse<String> response = Unirest.get(url) .basicAuth("myUsername", "myToken") .header("Cache-Control", "no-cache") .asString(); System.out.println("Response content: " + response.getBody()); } }
<?php $auth_basic = base64_encode("myUsrname:myToken"); $curl = curl_init(); $env = "verifApp"; $phone_number = "12015550123"; $code = "652871"; $url = 'https://api.labsmobile.com/otp/validateCode?'; $url .= 'env='. urlencode($env) .'&'; $url .= 'phone_number=' . urlencode($phone_number) .'&'; $url .= 'code=' . urlencode($code) .'&'; 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', CURLOPT_HTTPHEADER => array( 'Authorization: Basic '.$auth_basic ), )); $response = curl_exec($curl); curl_close($curl); echo $response;
import requests, base64, urllib.parse userToken = "myUsername:myToken" credentials = (base64.b64encode(userToken.encode()).decode()) data = { 'env':'verifApp', 'phone_number': '12015550123', 'code': '652871', } url = "https://api.labsmobile.com/otp/validateCode?"+urllib.parse.urlencode(data, doseq=True) payload = {} headers = { 'Authorization': 'Basic %s' % credentials, } response = requests.request("GET", url, headers=headers, data=payload) print(response.text)
const axios = require('axios'); const env = "verifApp"; const phone_number = "12015550123"; const code = "652871"; let config = { method: 'get', maxBodyLength: Infinity, url: `https://api.labsmobile.com/otp/validateCode?env=${encodeURIComponent(env)}&phone_number=${encodeURIComponent(phone_number)}&code=${encodeURIComponent(code)}`, headers: { 'Authorization': 'Basic ' + Buffer.from("myUsername:myToken").toString('base64') }, }; axios.request(config) .then((response) => { console.log(JSON.stringify(response.data)); }) .catch((error) => { console.log(error); });
require "uri" require 'base64' require "net/http" url = URI("https://api.labsmobile.com/otp/validateCode") data = { 'env' => 'verifApp', 'phone_number' => '12015550123', 'code' => '652871', } url.query = URI.encode_www_form(data) https = Net::HTTP.new(url.host, url.port) https.use_ssl = true request = Net::HTTP::Get.new(url) request["Authorization"] = "Basic " + Base64.strict_encode64("myUsername:myToken") response = https.request(request) puts response.read_body
Check OTP code
Checking the status of the OTP code corresponding to a specific number and environment.
ENDPOINT
GET https://api.labsmobile.com/otp/checkCode
PARAMETERS
phone_number string mandatory
Phone number to be checked and get the status of its OTP code.
Example:
&phone_number=167923402323
env string
Environment where this petition is framed.
Example:
&env=VerifApp
.RESULT
The result is obtained in the body of the HTTP response and can contain the following values:
Status values0
OTP code does not exist for this number and environment or is pending validation. 1
OTP code successfully validated.
curl --user myUsername:myToken -X GET \ https://api.labsmobile.com/otp/checkCode?env=verifApp&phone_number=12015550123
#include <stdio.h> #include <curl/curl.h> int main(void) { CURL *curl; CURLcode res; char *env = "verifApp"; char *phone_number = "12015550123"; curl = curl_easy_init(); if(curl) { char *encoded_env = curl_easy_escape(curl, env, 0); char *encoded_phone_number = curl_easy_escape(curl, phone_number, 0); char url[1024]; snprintf(url, sizeof(url), "https://api.labsmobile.com/otp/checkCode?env=%s&phone_number=%s", encoded_env, encoded_phone_number); curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET"); curl_easy_setopt(curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_BASIC); curl_easy_setopt(curl, CURLOPT_USERNAME, "myUsername"); curl_easy_setopt(curl, CURLOPT_PASSWORD, "myToken"); res = curl_easy_perform(curl); if(res != CURLE_OK) { fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); } curl_free(encoded_env); curl_free(encoded_phone_number); curl_easy_cleanup(curl); } return 0; }
using System; using RestSharp; namespace SendOtp { class Program { static void MainSend(string[] args) { var client = new RestClient("https://api.labsmobile.com"); var request = new RestRequest("/otp/checkCode", Method.Get); request.AddQueryParameter("env", "verifApp"); request.AddQueryParameter("phone_number", "12015550123"); request.AddHeader("Cache-Control", "no-cache"); 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; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; public class App { public static void main(String[] args) throws UnirestException, UnsupportedEncodingException { String env = URLEncoder.encode("verifApp", "UTF-8"); String phoneNumber = URLEncoder.encode("12015550123", "UTF-8"); String url = String.format("https://api.labsmobile.com/otp/checkCode?env=%s&phone_number=%s", env, phoneNumber); Unirest.setTimeouts(0, 0); HttpResponse<String> response = Unirest.get(url) .basicAuth("myUsername", "myToken") .header("Cache-Control", "no-cache") .asString(); System.out.println("Response content: " + response.getBody()); } }
<?php $auth_basic = base64_encode("myUsrname:myToken"); $curl = curl_init(); $env = "verifApp"; $phone_number = "12015550123"; $url = 'https://api.labsmobile.com/otp/checkCode?'; $url .= 'env='. urlencode($env) .'&'; $url .= 'phone_number=' . urlencode($phone_number) .'&'; 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', CURLOPT_HTTPHEADER => array( 'Authorization: Basic '.$auth_basic ), )); $response = curl_exec($curl); curl_close($curl); echo $response;
import requests, base64, urllib.parse userToken = "myUsername:myToken" credentials = (base64.b64encode(userToken.encode()).decode()) data = { 'env':'verifApp', 'phone_number': '12015550123', } url = "https://api.labsmobile.com/otp/checkCode?"+urllib.parse.urlencode(data, doseq=True) payload = {} headers = { 'Authorization': 'Basic %s' % credentials, } response = requests.request("GET", url, headers=headers, data=payload) print(response.text)
const axios = require('axios'); const env = "verifApp"; const phone_number = "12015550123"; let config = { method: 'get', maxBodyLength: Infinity, url: `https://api.labsmobile.com/otp/checkCode?env=${encodeURIComponent(env)}&phone_number=${encodeURIComponent(phone_number)}`, headers: { 'Authorization': 'Basic ' + Buffer.from("myUsername:myToken").toString('base64') }, }; axios.request(config) .then((response) => { console.log(JSON.stringify(response.data)); }) .catch((error) => { console.log(error); });
require "uri" require 'base64' require "net/http" url = URI("https://api.labsmobile.com/otp/checkCode") data = { 'env' => 'verifApp', 'phone_number' => '12015550123', } url.query = URI.encode_www_form(data) https = Net::HTTP.new(url.host, url.port) https.use_ssl = true request = Net::HTTP::Get.new(url) request["Authorization"] = "Basic " + Base64.strict_encode64("myUsername:myToken") response = https.request(request) puts response.read_body
List environments
Consult all the environments created by an account.
ENDPOINT
GET https://api.labsmobile.com/otp/getEnvList
This function has no parameters and generates a result in JSON
format with the list of environments.
curl --user myUsername:myToken -X GET \ https://api.labsmobile.com/otp/getEnvList
#include <stdio.h> #include <curl/curl.h> int main(void) { CURL *curl; CURLcode res; curl = curl_easy_init(); if(curl) { char url[1024]; snprintf(url, sizeof(url),"https://api.labsmobile.com/otp/getEnvList"); curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET"); curl_easy_setopt(curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_BASIC); curl_easy_setopt(curl, CURLOPT_USERNAME, "myUsername"); curl_easy_setopt(curl, CURLOPT_PASSWORD, "myToken"); 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 SendOtp { class Program { static void MainSend(string[] args) { var client = new RestClient("https://api.labsmobile.com"); var request = new RestRequest("/otp/getEnvList", Method.Get); request.AddHeader("Cache-Control", "no-cache"); 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; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; public class App { public static void main(String[] args) throws UnirestException, UnsupportedEncodingException { String url = String.format("https://api.labsmobile.com/otp/getEnvList"); Unirest.setTimeouts(0, 0); HttpResponse<String> response = Unirest.get(url) .basicAuth("myUsername", "myToken") .header("Cache-Control", "no-cache") .asString(); System.out.println("Response content: " + response.getBody()); } }
<?php $auth_basic = base64_encode("myUsrname:myToken"); $curl = curl_init(); $url = 'https://api.labsmobile.com/otp/getEnvList'; 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', CURLOPT_HTTPHEADER => array( 'Authorization: Basic '.$auth_basic ), )); $response = curl_exec($curl); curl_close($curl); echo $response;
import requests, base64 userToken = "myUsername:myToken" credentials = (base64.b64encode(userToken.encode()).decode()) url = "https://api.labsmobile.com/otp/getEnvList" payload = {} headers = { 'Authorization': 'Basic %s' % credentials, } response = requests.request("GET", url, headers=headers, data=payload) print(response.text)
const axios = require('axios'); let config = { method: 'get', maxBodyLength: Infinity, url: `https://api.labsmobile.com/otp/getEnvList`, headers: { 'Authorization': 'Basic ' + Buffer.from("myUsername:myToken").toString('base64') }, }; axios.request(config) .then((response) => { console.log(JSON.stringify(response.data)); }) .catch((error) => { console.log(error); });
require "uri" require 'base64' require "net/http" url = URI("https://api.labsmobile.com/otp/getEnvList") https = Net::HTTP.new(url.host, url.port) https.use_ssl = true request = Net::HTTP::Get.new(url) request["Authorization"] = "Basic " + Base64.strict_encode64("myUsername:myToken") response = https.request(request) puts response.read_body
{"verifApp", "verifApp2", "envEx"}
List OTP codes
Query OTP codes of an environment or associated to a number.
ENDPOINT
GET https://api.labsmobile.com/otp/getEnv
PARAMETERS
The
env
andmsidn
parameters are filters to obtain the sent OTP codes. They are optional filters and if no parameter is sent, all the OTP codes of the account will be obtained as results.env string
Filter of the environment where this request is framed. All numbers in this environment will be returned.
Example:
&env=VerifApp
.phone_number string
Number filter. All OTP codes of this number will be returned.
Example:
&phone_number=167923402323
RESULT
The result is obtained in
JSON
format with the list of codes with the following elements:msisdn string
Number associated with the OTP code.
status 0 | 1 | 2
Status of the OTP code or validation request.
Status values0
OTP code without successful validation. 1
OTP code successfully validated. 2
OTP code with expired validation. created YYYY-MM-DD HH:MM:SS
Day and time (in UTC time zone) of OTP code creation.
validated YYYY-MM-DD HH:MM:SS
Day and time (in UTC time zone) of OTP code validation. Null value if there is no successful validation.
curl --user myUsername:myToken -X GET \ https://api.labsmobile.com/otp/getEnv?env=verifApp&phone_number=12015550123
#include <stdio.h> #include <curl/curl.h> int main(void) { CURL *curl; CURLcode res; char *env = "verifApp"; char *phone_number = "12015550123"; curl = curl_easy_init(); if(curl) { char *encoded_env = curl_easy_escape(curl, env, 0); char *encoded_phone_number = curl_easy_escape(curl, phone_number, 0); char url[1024]; snprintf(url, sizeof(url), "https://api.labsmobile.com/otp/getEnv?env=%s&phone_number=%s", encoded_env, encoded_phone_number); curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET"); curl_easy_setopt(curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_BASIC); curl_easy_setopt(curl, CURLOPT_USERNAME, "myUsername"); curl_easy_setopt(curl, CURLOPT_PASSWORD, "myToken"); res = curl_easy_perform(curl); if(res != CURLE_OK) { fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); } curl_free(encoded_env); curl_free(encoded_phone_number); curl_easy_cleanup(curl); } return 0; }
using System; using RestSharp; namespace SendOtp { class Program { static void MainSend(string[] args) { var client = new RestClient("https://api.labsmobile.com"); var request = new RestRequest("/otp/getEnv", Method.Get); request.AddQueryParameter("env", "verifApp"); request.AddQueryParameter("phone_number", "12015550123"); request.AddHeader("Cache-Control", "no-cache"); 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; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; public class App { public static void main(String[] args) throws UnirestException, UnsupportedEncodingException { String env = URLEncoder.encode("verifApp", "UTF-8"); String phoneNumber = URLEncoder.encode("12015550123", "UTF-8"); String url = String.format("https://api.labsmobile.com/otp/getEnv?env=%s&phone_number=%s", env, phoneNumber); Unirest.setTimeouts(0, 0); HttpResponse<String> response = Unirest.get(url) .basicAuth("myUsername", "myToken") .header("Cache-Control", "no-cache") .asString(); System.out.println("Response content: " + response.getBody()); } }
<?php $auth_basic = base64_encode("myUsrname:myToken"); $curl = curl_init(); $env = "verifApp"; $phone_number = "12015550123"; $url = 'https://api.labsmobile.com/otp/getEnv?'; $url .= 'env='. urlencode($env) .'&'; $url .= 'phone_number=' . urlencode($phone_number) .'&'; 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', CURLOPT_HTTPHEADER => array( 'Authorization: Basic '.$auth_basic ), )); $response = curl_exec($curl); curl_close($curl); echo $response;
import requests, base64, urllib.parse userToken = "myUsername:myToken" credentials = (base64.b64encode(userToken.encode()).decode()) data = { 'env':'verifApp', 'phone_number': '12015550123', } url = "https://api.labsmobile.com/otp/getEnv?"+urllib.parse.urlencode(data, doseq=True) payload = {} headers = { 'Authorization': 'Basic %s' % credentials, } response = requests.request("GET", url, headers=headers, data=payload) print(response.text)
const axios = require('axios'); const env = "verifApp"; const phone_number = "12015550123"; let config = { method: 'get', maxBodyLength: Infinity, url: `https://api.labsmobile.com/otp/getEnv?env=${encodeURIComponent(env)}&phone_number=${encodeURIComponent(phone_number)}`, headers: { 'Authorization': 'Basic ' + Buffer.from("myUsername:myToken").toString('base64') }, }; axios.request(config) .then((response) => { console.log(JSON.stringify(response.data)); }) .catch((error) => { console.log(error); });
require "uri" require 'base64' require "net/http" url = URI("https://api.labsmobile.com/otp/getEnv") data = { 'env' => 'verifApp', 'phone_number' => '12015550123', } url.query = URI.encode_www_form(data) https = Net::HTTP.new(url.host, url.port) https.use_ssl = true request = Net::HTTP::Get.new(url) request["Authorization"] = "Basic " + Base64.strict_encode64("myUsername:myToken") response = https.request(request) puts response.read_body
[ {"34609033271", "1", "2016-01-03 12:32:08", "2016-01-03 12:34:40"}, {"34699293203", "2", "2016-01-05 12:32:10", "2016-01-06 23:22:52"} ]
Errors
The HTTP error codes that may be returned by a request to the OTP API are described below.
200 | OK | Operation processed correctly. |
400 | Bad Request | Error in one of the parameters. |
401 | Unauthorized | Error in the credentials provided. |
403 | Forbidden | Request blocked by security filters or misuse. |
404 | Not Found | Request or command does not exist. |
500 | Internal Server Error | Internal or unknown error. |
Support resources
We recommend that you consult and take into account the following support resources in your integration:
- Description, manual and code examples of the SMS sending API.
- Technical guide to an OTP validation or authentication process by SMS.
- All LabsMobile API versions and functionalities.
- First Steps to API Integration Tutorial
- Create a demo account
- Recommendations and best practices in any integration.
- Plugins, modules and extensions.
- Need help? Contact our technicians