SMS API

Last updated: June 14th, 2021

Generate OTP Code

Call this API to generate an OTP verification code.

Endpoint:

https://api.esms.com.my/sms/otp/generate

Method:

POST, supported content-type are:

  • application/x-www-form-urlencoded; charset=utf-8
  • application/json; charset=utf-8

* charset behind is necessary when you're sending in Unicode content, such as Chinese characters.

Parameters:
Name Type Required Description
api-key String Mandatory This would be your account's api key.
api-secret String Mandatory This would be your account's api secret.
phone String Mandatory

The phone number of target recipient you'd like to send OTP to.

Phone number must be supplied along with country code.

Do not include any non-numeric character, eg: - ( ) or space.

Example: 60123456789

brand-name String Optional
(either brand-name or message is needed)

The title of your company or app name.

Example: If you send Eaon, your user will receive the content as:

RM0.00 Eaon - Your OTP code is 112233. This is valid for the next 3 minutes.

message String Optional
(either brand-name or message is needed)

Your own version of SMS content. Please include "#otp#" and "#duration#" to be replaced with automated parameters.

Example: If you send
RM0.00 Eaon - Your OTP code is #otp#. This is valid for the next #duration# minutes.

Your user will receive the content as:
RM0.00 Eaon - Your OTP code is 112233. This is valid for the next 3 minutes.

duration Numeric Optional (default as 3)

The duration a OTP code should stay valid, duration is measured in minute. Maximum of 9 minutes.

Example: 1

app-id Numeric Optional (default as 1)

Useful when you use single account to handle multiple system's OTP code.

For example, you should always send 1 for your first system, and always send 2 for your second system, so the verification does not conflict among different apps on your end

language String Optional (default as en)

Only effective if you're sending brand-name,

Possible values: en / my / zh

Response:

Response would be returned in application/json format.

An example of Successful response would be:

{"status":0,"creditDeducted":1,"message":"ok","id":"88ce9c6e-1707-41b8-95a2-91d228001fc7","parts":1,"type":0}

An example of Failed response would be:

{"status":9,"message":"Invalid phone number, please do not include any non-numeric character","id":"c8d6bb1c-bff6-47d5-9e01-dc2596bbdbe7"}

Name Type Description
status Numeric Status code of the request, kindly refer to below Status mapping table for more details
message String A short description of given status, for more information you may contact our support team at support@esms.com.my
id String ID of this particular request, you may want to keep this ID in your own table for future reference.
creditDeducted Numeric The total credit amount deducted from your account.
parts Numeric To show how many parts of SMS this message requires.
type Numeric

Type of this SMS, "0" for normal (ASCII) SMS, "8" for unicode SMS.

If you submitted a valid type during the request, it would be used, otherwise this would be automatically detected.

Response Status Code:
Status Code Description
0Success.
1Insufficient parameters
Please make sure all mandatory parameter exists.
2Invalid calling IP
You are getting this error because you've previously requested your account to be able to call only from certain IP, and you're not calling from the designated IP.
3Invalid api key/secret combination.
If you believe this is an error, kindly contact our support team at support@esms.com.my.
4Invalid country code
The country code of the phone number you provides is not recognized.
For Malaysia recipients, do remember to send to 60123456789 instead of 0123456789.
5Insufficient credits
Contact your account manager for reload procedures.
6Internal error
You may retry again shortly.
8Content too long
Final SMS can only contains maximum of 160 GSM characters for Normal SMS, and 70 characters for Unicode SMS.
9Invalid "phone" parameter
Please include only numeric in "phone" parameter
For example, please send 60123456789 instead of 60-12 345 6789
10Invalid message content
For SMS to Malaysia mobile phones, you're required to append RM0.00<space> at the front of the message
For example, intead of sending Eaon - Thank you for purchasing product A.
You should send RM0.00 Eaon - Thank you for purchasing product A.
11Brand name or Message required
Please make sure you supply either "brand-name" or "message" in request body.
12Message missing #otp#
If you're sending "message" parameter, please make sure you include #otp# in the message content.
13Brand name too long
Brand name support only maximum of 20 characters.
14Invalid Duration
Maximum supported duration is 9 minutes
15Invalid language code
Please only use en, my, or zh in "language" parameter
JSON Request Sample:

Simple (using brand name)

{
	"api-key": "<your api key>",
	"api-secret": "<your api secret>",
	"phone": "60123456789",
	"brand-name": "Eaon"
}
										

Complete (using brand name)

{
	"api-key": "<your api key>",
	"api-secret": "<your api secret>",
	"phone" : "60123456789",
	"brand-name" : "Eaon",
	"language" : "en",
	"duration" : 5,
	"app-id" : 2
}
										

Simple (using message)

{
	"api-key": "<your api key>",
	"api-secret": "<your api secret>",
	"phone": "60123456789",
	"message": "RM0.00 Eaon - Your OTP code is #otp#. This is valid for the next #duration# minutes."
}
										

Complete (using message)

{
	"api-key": "<your api key>",
	"api-secret": "<your api secret>",
	"phone" : "60123456789",
	"message": "RM0.00 Eaon - Your OTP code is #otp#. This is valid for the next #duration# minutes."
	"duration" : 5,
	"app-id" : 2
}