RotsiDocs
  • 😃Welcome to ROTSI API Documentation
  • Reference
    • API Reference
      • STK Push
      • B2C Disbursements
      • Paybill
      • BuyGoods
      • Bank Payments
        • Bank Code List
      • Bulk SMS
      • Thank you Page
Powered by GitBook
On this page
  1. Reference
  2. API Reference

Bulk SMS

This API enables you to send as many SMSs as you would like (Bulk SMS).

PreviousBank Code ListNextThank you Page

Last updated 1 year ago

This endpoint allows you to send to send as many SMSs as possible. We are using Kafka to ensure that all your messages are processed and sent. We will also pre-process your object body inorder to remove duplicate messages.

One SMS will cost you a small fee of 0.5/= per SMS. You will not be charged for messages are found during pre-processing.

Endpoint for the API request.

POST

Request Body

Name
Type
Description

username*

string

The username of the account, as per the Rotsi Dashboard.

body*

Object

messages: Type: Array of Objects

Description: An array where each element is an object representing a single SMS message to be sent. Each message object contains the following fields:

phone:

Type: String Description: The recipient's phone number. This should include the country code if applicable. Example: "0745474586" message:

Type: String Description: The text content of the SMS message to be sent. This field contains the actual message that will be delivered to the recipient. Example: "This is a test message 4,"

const axios = require('axios');

const data = {
  username: "username",
  body: {
    messages: [
      { phone: "0722000000", message: "This is a test message 1," },
      { phone: "0722000000", message: "This is a test message 2," },
      { phone: "0722000000", message: "This is a test message 3," }
    ]
  }
};

const config = {
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'secret_key'
  }
};

axios.post('https://api.rotsi.co.ke/sms/bulksms/v1', data, config)
  .then(response => {
    console.log(response.data);
  })
  .catch(error => {
    console.error(error);
  });
import requests

url = "https://api.rotsi.co.ke/sms/bulksms/v1"
headers = {
    'Content-Type': 'application/json',
    'Authorization': 'secret_key'
}
data = {
    "username": "username",
    "body": {
        "messages": [
            { "phone": "0722000000", "message": "This is a test message 4," },
            { "phone": "0722000000", "message": "This is a test message 4," },
            { "phone": "0722000000", "message": "This is a test message 4," }
        ]
    }
}

response = requests.post(url, headers=headers, json=data)
print(response.json())
require 'net/http'
require 'uri'
require 'json'

uri = URI.parse("https://api.rotsi.co.ke/sms/bulksms/v1")
request = Net::HTTP::Post.new(uri)
request.content_type = "application/json"
request["Authorization"] = "secret_key"
request.body = JSON.dump({
  "username" => "username",
  "body" => {
    "messages" => [
      { "phone" => "0722000000", "message" => "This is a test message 4," },
      { "phone" => "0722000000", "message" => "This is a test message 4," },
      { "phone" => "0722000000", "message" => "This is a test message 4," },
      { "phone" => "0722000000", "message" => "This is a test message 4," }
    ]
  }
})

response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
  http.request(request)
end

puts response.body
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;

public class ApiRequest {
    public static void main(String[] args) {
        try {
            URL url = new URL("https://api.rotsi.co.ke/sms/bulksms/v1");
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("POST");
            connection.setRequestProperty("Content-Type", "application/json");
            connection.setRequestProperty("Authorization", "secret_key");
            connection.setDoOutput(true);

            String jsonInputString = "{"
                    + "\"username\": \"username\","
                    + "\"body\": {"
                    + "\"messages\": ["
                    + "{\"phone\": \"0722000000\", \"message\": \"This is a test message 4,\"},"
                    + "{\"phone\": \"0722000000\", \"message\": \"This is a test message 4,\"},"
                    + "{\"phone\": \"0722000000\", \"message\": \"This is a test message 4,\"},"
                    + "{\"phone\": \"0722000000\", \"message\": \"This is a test message 4,\"}"
                    + "]"
                    + "}"
                    + "}";

            try (OutputStream os = connection.getOutputStream()) {
                byte[] input = jsonInputString.getBytes(StandardCharsets.UTF_8);
                os.write(input, 0, input.length);
            }

            int code = connection.getResponseCode();
            System.out.println("Response Code: " + code);
            // Read response if needed

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
<?php

$url = "https://api.rotsi.co.ke/sms/bulksms/v1";
$data = array(
    "username" => "username",
    "body" => array(
        "messages" => array(
            array("phone" => "0722000000", "message" => "This is a test message 4,"),
            array("phone" => "0722000000", "message" => "This is a test message 4,"),
            array("phone" => "0722000000", "message" => "This is a test message 4,"),
            array("phone" => "0722000000", "message" => "This is a test message 4,")
        )
    )
);
$headers = array(
    'Content-Type: application/json',
    'Authorization: secret_key'
);

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));

$response = curl_exec($ch);

if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
} else {
    echo $response;
}

curl_close($ch);

?>
curl -X POST \
  https://api.rotsi.co.ke/sms/bulksms/v1 \
  -H 'Content-Type: application/json' \
  -H 'Authorization: secret_key' \
  -d '
    {
  "username": "username",
  "body": {
    "messages": [
      {
        "phone": "0722000000",
        "message": "This is a test message 4,"
      },
      {
        "phone": "0722000000",
        "message": "This is a test message 4,"
      },
      {
        "phone": "0722000000",
        "message": "This is a test message 4,"
      }
    ]
  }
}'
{
    status: "Success",
    Service: "RotsiBulkSmsService",
    TimeCreated: Date.now(),
    ResponseMessage: `Sent to ${successfulCount}/${initialBatchSize}. Total Cost: KES ${totalCost}`,
    UnsuccessfulMessages: unsuccessfulMessages
}
{ 
"status": "Failed",
"Service": "RotsiB2C",
"message": "Payment request cancelled by the user",
"RotsiAPITransactionId": PBP719hcbjh2,
}

If youre under demo clients, ensure youre balance is sufficient to send the messages. Minimum account Balance is 10KES. Eg. If youre total cost is 10, ensure your balance is 20KES or more. If youre an active business using your own shortcode via the Rotsi EcoSystem, ensure your services balance is sufficient. Check the balance in the Dashboard Portal.

If you would like you`re own senderID to be sent along with the message. Contact us via email at : support@rotsi.co.ke, with the Subject :"Request for SenderID", along with your suggested senderID, and we will reply alerting you if it is available and documents required to be submitted.

https://api.rotsi.co.ke/sms/bulksms/v1