Sending an SMS
To send an SMS, replace the following variables in the example below:
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). |
SENDLIME_BRAND_NAME | The registered brand or purchased number. |
TO_NUMBER | The phone number you are sending the message to. |
- 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-sms.sh
:
curl -X "POST" "https://brain.sendlime.com/sms" \
-d "from=$SENDLIME_BRAND_NAME" \
-d "text=A text message sent using the SendLime API" \
-d "to=$TO_NUMBER" \
-u $SENDLIME_API_KEY:$SENDLIME_API_SECRET
info
If you don't have any approved brand or any purchased number, you don't need to pass from
. We will send the SMS from a random number.
Run your code
Save this file to your machine and run it:
sh send-sms.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
const from = SENDLIME_BRAND_NAME;
const to = TO_NUMBER;
const text = "A text message sent using the SendLime API";
sendLime.message
.sendSms({ from, to, text })
.then((response) => {
if (response.success) {
console.log("Message sent successfully.");
} else {
console.log(`Message failed with error: ${response.error_message}`);
}
})
.catch((err) => console.log(err));
info
If you don't have any approved brand or any purchased number, you don't need to pass from
. We will send the SMS from a random number.
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();
SendMessageResponse networkResponse = client.getSmsClient().sendMessage(
SENDLIME_BRAND_NAME,
TO_NUMBER,
"A text message sent using the SendLime API"
);
if (response.isSuccess()) {
System.out.println("Message sent successfully");
} else {
System.out.println("Message failed with error: " + response.getErrorMessage());
}
info
If you don't have any approved brand or any purchased number, you don't need to pass the first argument to the sendMessage
function. We will send the SMS from a random number.
Try it out
When you run the example above, the text message will be sent to the mobile number that you specified.
caution
As per the BTRC guidelines, promotional messages have to be in Bangla.