Send Verification Code
When you have collected a user's phone number, start the verification process by sending a verify request to the Verify API.
The Verify API returns a request_id
. Use this to make a check request to see if the user provided the correct code.
Replace the following variables in the sample code with your own values:
Key | Description |
---|---|
SENDLIME_API_KEY | Your SendLime API key (see it on your dashboard). |
SENDLIME_API_SECRET | Your SendLime API secret (see it on your dashboard). |
TO_NUMBER | The phone number to verify. |
BRAND_NAME | Included in the message to explain who is confirming the phone number. |
info
Each verification code is valid for 10 minutes. Subsequent calls to the API before the code has expired will send the same verification code. You cannot modify the amount of time a verification code is valid.
- cURL
- Node.js
- Java
info
HTTP requests to the API are protected with HTTP Basic authentication.
User your API Key as the username and your API Secret as the password for HTTP Basic authentication.
Write the code
Add the following to send-verification-code.sh
:
curl -X "POST" "https://brain.sendlime.com/verify" \
-d "phone_number=$TO_NUMBER" \
-d "brand=$BRAND_NAME" \
-u $SENDLIME_API_KEY:$SENDLIME_API_SECRET
Run your code
Save this file to your machine and run it:
sh send-verification-code.sh
Install the library
npm install @sendlime/server-sdk
Initialize the library
const SendLime = require('@sendlime/server-sdk');
const sendLime = new SendLime({
apiKey: SENDLIME_API_KEY,
apiSecret: SENDLIME_API_SECRET,
});
Write the code
sendLime.verify
.sendCode({
brand: BRAND_NAME,
phone_number: TO_NUMBER,
code_length: 6,
locale: 'en-us',
})
.then((res) => {
if (res.success) {
console.log(`request_id: ${res.result.request_id}`);
} else {
console.log(`Failed with error: ${res.error_message}`);
}
})
.catch((err) => console.log(err));
Installation
Gradle
Step 1. Add the JitPack repository to your build file
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
implementation 'com.github.SendLime:sendlime-sdk-java:v1.0.11'
}
Maven
Step 1. Add the JitPack repository to your build file
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Step 2. Add the dependency
<dependency>
<groupId>com.github.SendLime</groupId>
<artifactId>sendlime-sdk-java</artifactId>
<version>v1.0.11</version>
</dependency>
Write the code
SendLimeClient client = SendLimeClient.build().apiKey(SENDLIME_API_KEY).apiSecret(SENDLIME_API_SECRET).build();
SendCodeResponse sendCodeResponse = client.getCodeClient().sendCode(BRAND_NAME, TO_NUMBER, "en-us", 6);
if (sendCodeResponse.isSuccess()) {
System.out.println(sendCodeResponse.getResult().getRequestId());
} else {
System.out.println(sendCodeResponse.getErrorMessage());
}
Try it out
When you run the example above, the verification code will be sent to the mobile number that you specified.