Introduction

>2-Factor Authentication is a security solution using cloud messaging technology to verify users and protect the system from being attacked. Each PIN code (use once) is generated and sent to users (sms or voice call). Users receive PIN code and enter into their app to verify. If PIN code is correct, users are allowed to take other steps to continue using the app. SpeedSMS 2-Factor Authentication API (2FA API) allows you to easily add another security layer into your system via the only API. Moreover, you can use 2FA API to generate and send verified code to users.

API URL

All API will start with the url address:

http://api.speedsms.vn/index.php/

Or

https://api.speedsms.vn/index.php/

You should use HTTPS address to ensure the security

Authentication

To use 2FA API, you need to register an account at: http://connect.speedsms.vn. Each account will be provided an API access token. Your app will use API access token to authenticate with SpeedSMS

API access token will be attachedly send with HTTP request via HTTP Basic Authentication. Therefore, API access token will be known as an username.

For example: To call API via curl:

curl -i -u “{API access token}:x” “https://api.speedsms.vn/index.php/user/info”

To get API access token, you need to log in at https://connect.speedsms.vn, select menu “Settings”->”Profile”

Rate limit

SpeedSMS 2FA API allows your app to call up to 60 requests within 60 seconds. If you exceed requests, you will receive the response: {“name”:”Too Many Requests”,”message”:”Rate limit exceeded.”,”code”:0,”status”:429} This time, you need to check the parameter X-Rate-Limit-Reset in HTTP’s header to get the seconds and carry out sleep mechanism before proceeding with the requests In case you need more than 60 requests, please contact us.

Error codes

  • 007: IP locked
  • 008: Account blocked
  • 009: Account not allow to call the API
  • 101: Invalid or missing parameters
  • 105: Phone number invalid
  • 300: Your account balance not enough to send sms
  • 500: Internal error, please try again
  • API generates PIN code

    PIN/pin/create API allows you to generate a PIN code and send this code to users according to the configuration of the previously 2FA application

    curl -i -u “{Access token}” -H “Content-Type: application/json” -X POST -d ‘{“to”: “phone number”, “content”: “noi dung sms”, “app_id”: “2FA Application ID”}’ https://api.speedsms.vn/index.php/pin/create

    Call API via curl:

    • to: PIN code receiver’s phone number (note: phone number is in the form of: 09x, 01x).
    • content: Message content – an optional parameter if voice call is used to send PIN code. In case of using sms to send PIN code, message needs to include keyword {pin_code}, this keyword will be replaced by PIN code that SpeedSMS generates
    • app_id: is your app ID code that you generated

    For example: {“to”: “0912345678”, “content”: “Your verification code is: {pin_code}”, “app_id”: “1234567890”}

    Success response:

    { “status”: “success”, “data”: { “pin”: “PIN code that users entered”, “phone”: “user’s phone number”, “verified”: true/fale, “remainingAttempts”: the number of times that the PIN code is re-entered if the previous error is entered incorrectly } }

    • pin_code: is PIN code that SpeedSMS successfully generated and sent to users
    • tranld: is used to check the status of recently sent sms/voice call
    • totalPrice: total cost which is based on the method you use to send PIN code

    Error response:

    { “status”: “error”, “code”: “error code”, “message”: “error description” }

    API verifies PIN code

    POST/pin/verify API allows you verify if users either enter PIN code correctly or not

    Call API via curl:

    curl -i -u “{Access token}” -H “Content-Type: application/json” -X POST -d ‘{“phone”: “phone number”, “app_id”: “Application id”, “pin_code”: ” PIN code entered by the user “}’ https://api.speedsms.vn/index.php/pin/verify

    • phone: PIN code receiver’s phone number (note: phone number is in the form of: 09x, 01x).
    • pin_code: is PIN code that users entered
    • app_id: is your app ID code that you generated

    Success response:

    { “status”: “success”, “data”: { “pin”: “PIN code that users entered”, “phone”: “user’s phone number”, “verified”: true/fale, “remainingAttempts”: the number of times that the PIN code is re-entered if the previous error is entered incorrectly } }

    pin: the pin code that users entered into their app
    phone: phone number receiving pin code
    verified: true/false (indicates that PIN code entered is true of false)
    remainingAttempts: the number of times that users are allowed to re-enter pin code if the previous error is entered incorrectly

    Error response:

    { “status”: “error”, “code”: “error code”, “message”: “error description” }

    Sample PHP code

    You can download sample code php here for preference.

    Sample Java code

    Download sample code for java language here

    Sample C# code

    Download sample code for C# language here