Verify OTP SMS in Java Bulk SMS API Documentation

Verify OTP SMS in Java

Verify One Time Password Token to the Recipient in Java.

Application API URL:

https://www.smsgateway.center/OTPApi/send

 

Import Verify OTP SMS API postman collection.

Postman Collection

 

 

Key Value Description
Login Credentials (Required Parameters)
Authenticate your API request using userId-password or apiKey. You should use either one to authenticate your login.
userId Your Registered Username The registered username parameter to be passed. You can use this if apiKey is not being used.
password Your password The password needs to be urlencoded if there are any special characters used in the password field. You can use this if apiKey is not being used.
apiKey Your unique apiKey apiKey needs to be sent as HTTP header when you are not using userId and password credentials. You can avail this from your user control panel and use instead of userId and password HTTP Request parameter. Please do not disclose this to anyone.
Required Parameters
mobile Mobile Number with Country Code Required. Enter your Customer's mobile number which needs to be verified.

Comments: Keep number in International format (with country code).
otp Sent OTP Code Required. Send the code to verify which was delivered to recipient.

Comments: Verify OTP Token of the recipient.
sendMethod verify

Required: This value required for verification of OTP code which was inputted by the recipient.

format plain|json|xml Value for response format.

System default is plain. If you need responses in JSON or XML then you have to give value as JSON or XML.

Save this Page on your Favorite Social Media

Sample Request Code

import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;


public class SMSGatewayCenter{

public static void main(String[] args)
{
//Your apikey key
String apiKey = "YourApiKey";
//OR
String userId = "YourUserName";
String password = "YourPassword";

//Send Method (generate|verify)
String sendMethod = "verify";

//Multiple mobiles numbers separated by comma
String mobile = "919999999999";

//Your message to terminate, URLEncode the content
String otp = "6789";

//response format
String format = "json";

//Prepare Url
URLConnection myURLConnection=null;
URL myURL=null;
BufferedReader reader=null;

//URL encode message
String urlencodedotp=URLEncoder.encode(otp);

//API End Point
String mainUrl="https://www.smsgateway.center/OTPApi/send?";

//API Paramters
StringBuilder sendSmsData= new StringBuilder(mainUrl);
sendSmsData.append("apiKey="+apiKey);
sendSmsData.append("&userId="+userId);
sendSmsData.append("&password="+password);
sendSmsData.append("&sendMethod="+sendMethod);
sendSmsData.append("&mobile="+mobile);
sendSmsData.append("&otp="+urlencodedotp);
sendSmsData.append("&format="+format);
//final string
mainUrl = sendSmsData.toString();
try
{
//prepare connection
myURL = new URL(mainUrl);
myURLConnection = myURL.openConnection();
myURLConnection.connect();
reader= new BufferedReader(new InputStreamReader(myURLConnection.getInputStream()));
//reading response
String response;
while ((response = reader.readLine()) != null)
//print response
System.out.println(response);

//finally close connection
reader.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}

Response - Success

{
    "status": "success",
    "mobile": "91xxxxxxxxxx",
    "transactionId": "74c286ad-8a74-4dcd-a2dd-6c936a95037b",
    "statusCode": "900",
    "reason": "OTP has been Verified Successfully."
}
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<simpleMessageSuccessResponse>
    <mobile>91xxxxxxxxxx</mobile>
    <status>success</status>
    <statusCode>900</statusCode>
    <reason>OTP has been Verified Successfully.</reason>
    <transactionId>2f8e3c68-2b6d-4125-b1f3-8d7914ae2530</transactionId>
</simpleMessageSuccessResponse>
status=success | mobile=91xxxxxxxxxx | reason=OTP has been Verified Successfully. |  transactionId=c30ec631-afcc-4810-ad01-372242df9c40 | errorCode=900

Response - Error

{
    "status": "error",
    "statusCode": "952",
    "reason": "OTP token is already verified."
}
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<errorResponse>
    <status>error</status>
    <statusCode>952</statusCode>
    <reason>OTP token is already verified.</reason>
</errorResponse>
status=error | errorCode=952 | reason=OTP token is already verified.