DEV Community

Cover image for API Guide to Setup OTP SMS Verification
AlinaJ
AlinaJ

Posted on

API Guide to Setup OTP SMS Verification

Requirements

If you want to send OTP SMS or enable SMS verification, you need to Register and create an account with Verify Now console.messagecentral.com/signUp Have a valid balance in your account to send OTPs.
You can use the test credits during integration to verify our services or test our SMS verification services for free.
REST API Base URL’s:
All Platform API endpoints below should be prefixed with the following URL:
https://cpaas.messagecentral.com

** These are the following steps to successfully send an otp to a mobile number:**

  1. Generate a token
  2. Make a post request to our ‘send otp’ API and pass the token in header
  3. Make a get request to our ‘validate otp’ API and pass the token in header

How to generate a token?

  1. Make a get request to auth/v1/authentication/token
  2. Add the ‘customerId’ field. This is a unique id for every customer.
  3. Add ‘country’ field. This is the country ISO code of the registered user.
  4. Add ‘email’ field. This is the email address of the registered user. (It’s optional)
  5. Add ‘key’ field. This is the Base 64 encrypted password of the registered user.
  6. Add ‘scope’ field. This is a request to generate a ‘NEW’ token for the registered user.

** Sample response:**

Image description

How to send OTP to a mobile number?

  1. Make a post request to /verification/v2/verification/send
  2. Add ‘customerId’ field. This is a unique Id for every customer.
  3. Add ‘countryCode’ field. This is the country code of the mobile number who will receive the otp
  4. Add ‘otpLength’ field. This is the OTP length. It’s an optional field and by default the value is 4, you can configure it up to 8 digits.
  5. Add ‘mobileNumber’ field. This is the number that receives the otp.
  6. Add ‘flowType’ field. Set this type to ‘SMS’
  7. Add ‘authToken’ generated using the token API and pass that as a header in send otp.

** Sample response:**

Image description

The response will have a verificationId that will be passed a parameter in the validate OTP API to validate the request.

How to validate an OTP?

  1. Make a get request to /verification/v2/verification/validateOtp.
  2. Add ‘customerId’ field. This is a unique Id for every customer.
  3. Add ‘code’ field. This is the OTP code sent to the end user.
  4. Add ‘verificationId’ field. This is the verification id generated in the send OTP API.
  5. Add ‘authToken’ generated using the token API and pass that as a header in send otp.

** Sample response:**

Image description

You can see our detailed SMS verification API documentation page for more details.

Top comments (0)