Send OTP SMS in Java Bulk SMS API Documentation

Send OTP SMS in Java

Generate One Time Password Token to the Recipient in Java.

Application API URL:


Import Send 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 Enter your Customer's mobile number which needs to be verified.

Comments: Keep number in International format (with country code).
senderId Approved Sender Name For Indian customers, sender name would be of 6 alpha characters. For International customers, sender name depends on country to country basis.
msgType text|unicode This is to define simple or UNICODE message. For simple English, you can give value as text or for non-English messages, give value as unicode.
sendMethod generate

Required: This value required for send OTP code to recipient's mobile number.

msg Your text message with $otp$ variable Message content to send. (Default Message Content: Your verification code is $otp$)

Comments: Include variable as {{OTP}}, rest content can be sent as per requirement.
Default Parameters (Optional)
codeExpiry Time in seconds Optional. Minimum 60 Seconds, Maximum 1800 Seconds, System default is 60 Seconds.

Comments: Expiry Time of OTP Token to Verify, in Seconds.
codeLength OTP Token Length Optional. Minimum Length 4, Maximum Length 10, System default Length is 4.

Comments: Number of Digits/Characters in Length for OTP Token.
codeType num|alpha|alphanum Optional. num for Numeric token, alpha for Alphabetic token and alphanum for AlphaNumeric token. System default is num.

Comments: Type of the OTP token to be generated.
retryExpiry Retry Time in seconds Optional. Minimum 15 Seconds, Maximum 1800 Seconds, System default is 60 Seconds.

Comments: Maximum time to allow your users to regenerate OTP. E.g. If you have set 60 seconds, then user cannot request OTP again for next 60 seconds.
renew true|false Optional. Set to True to resend/regenerate new OTP Token. System default is false.

Comments: If OTP token needs to be resent/regenerated.
medium sms|email Optional. Name of the medium to deliver OTP to. You can deliver on 2 medium simultaneously. System default is sms.

Comments: You can use comma separated with maximum 2 mediums, that is sms,email. OTP token will be delivered to both sms and email.
emailId valid Email ID Optional. Give valid email id to deliver OTP code. Use only if OTP needs to be delivered to customer's Email ID.System default is null.

Comments: From Email ID will be shown as registered Email ID and From Name will be shown as Registered Full Name as per your account settings.
callback Valid callback script URL with http or https protocol Optional. To save data on your database or by capturing the response you can further email or use voice call to send OTP token.

Comments: To receive generated OTP token details, you can set a callback URL. Response Parameters will be sent to your url as status=success&type=new&generationTime=2017-12-06%2023%3A18%3A15&validity=120%20secs&otp=6754
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


public class SMSGatewayCenter{

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

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

//Message type text/unicode
String msgType = "text";

//Multiple mobiles numbers separated by comma
String mobile = "919999999999";
//Your approved sender id
String senderId = "SGCSMS";
//Your message to terminate, URLEncode the content
String msg = "Your SMSGatewayCenter OTP Code is $otp$";

//Final OTP Code Expiry
String codeExpiry = "600";

//OTP Code Length
String codeLength = "6";

//OTP Code Type
String codeType = "num";

//Retry After time
String retryExpiry = "60";

//set to true if you need to regenerate new OTP while resending OTP code
String renew = "false";

//Valid http url to receive response on your server. E.g
String callback = "";

//use comma separated for multiple. E.g. sms,email
String medium = "sms";

//if medium is used with comma separated for multiple. E.g. sms,email then use valid user's email address
String emailId = "";

//response format
String format = "json";

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

//URL encode message
String urlencodedmsg=URLEncoder.encode(msg);

//API End Point
String mainUrl="";

//API Paramters
StringBuilder sendSmsData= new StringBuilder(mainUrl);
//final string
mainUrl = sendSmsData.toString();
//prepare connection
myURL = new URL(mainUrl);
myURLConnection = myURL.openConnection();
reader= new BufferedReader(new InputStreamReader(myURLConnection.getInputStream()));
//reading response
String response;
while ((response = reader.readLine()) != null)
//print response

//finally close connection
catch (IOException e)

Response - Success

    "status": "success",
    "mobile": "91xxxxxxxxxx",
    "transactionId": "aa40b4b8-7bb8-4bf6-b94a-fa5b82df4511",
    "statusCode": "900",
    "type": "new",
    "reason": "OTP successfully generated.",
    "createTime": "1513772384340",
    "expiryTime": "1513772444340",
    "retryAfter": "1513772444340"
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <reason>OTP successfully generated.</reason>
status=success | mobile=91xxxxxxxxxx | reason=OTP successfully generated. | transactionId=975d55f6-f983-4a79-907e-71f69a62154b | errorCode=900 | type=new | createTime=1513772280207 | expiryTime=1513772340207 | retryExpiry=1513772340207

Response - Error

    "status": "error",
    "statusCode": "922",
    "reason": "Invalid mobile numbers."
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <reason>Invalid mobile numbers.</reason>
status=error | errorCode=922 | reason=Invalid mobile numbers.