API Guide to Setup OTP SMS Verification
Tags: otp, sms, smsverification
Published: 2024-01-15 15:52:37

## Requirements
If you want to send OTP SMS or enable [SMS verification][1], you need to Register and [create an account with Verify Now][2] 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][3]. 
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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e2hi9ub8ngea7k2f60qd.png)

## 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fxyu8srxgcdwdms83ns0.png)


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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/phaghz5k7y9vwefjb7q6.png)

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


  [1]: https://www.messagecentral.com/product/verify-now/overview
  [2]: https://console.messagecentral.com/signUp
  [3]: https://www.messagecentral.com/product/verify-now/free-sms-verification
  [4]: https://www.messagecentral.com/product/verify-now/api