Appearance
Shara Sms Api
This is the documentation for the Shara Sms Api. The api is used to send sms messages to multiple phone numbers. The api has three types of messages, Bulk, Subscription and On Demand messages.
Base URL: https://app.sharasms.co.ke/
Authentication
In the header of every request, you need to include the following header
http
Authorization: Bearer <access_token>You can manage your access token from the dashboard here: https://portal.sharasms.co.ke/api/documentation/tab/api_tokens
BulkSms
Sending a Bulk sms
http
curl -X POST https://app.sharasms.co.ke/api/messages/new \
-H "Authorization: Bearer <access_token>" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{
"message": "Hello, this is a test message",
"phone": "2547xxxxxxxx",
"short_code_id": "<short_code_id>"
}'php
$url = 'https://app.sharasms.co.ke/api/messages/new';
$accessToken = '<access_token>'; // Replace <access_token> with your actual access token
$shortCodeId = '<short_code_id>'; // Replace <short_code_id> with your actual short code ID
$data = [
'message' => 'Hello, this is a test message',
'phone' => '2547xxxxxxxx',
'short_code_id' => $shortCodeId,
];
$headers = [
'Authorization: Bearer ' . $accessToken,
'Content-Type: application/json',
'Accept: application/json',
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
echo $response;Subscription Sms
For subscription message, make sure the phone number is already subscribed to the short code
http
curl -X POST https://app.sharasms.co.ke/api/messages/new/subscription \
-H "Authorization: Bearer <access_token>" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{
"message": "Hello, this is a test message",
"phone": "2547xxxxxxxx",
"short_code_id": "<short_code_id>"
}'php
$url = 'https://app.sharasms.co.ke/api/messages/new/subscription';
$accessToken = '<access_token>'; // Replace <access_token> with your actual access token
$shortCodeId = '<short_code_id>'; // Replace <short_code_id> with your actual short code ID
$data = [
'message' => 'Hello, this is a test message',
'phone' => '2547xxxxxxxx', // Replace with the actual phone number
'short_code_id' => $shortCodeId,
];
$headers = [
'Authorization: Bearer ' . $accessToken,
'Content-Type: application/json',
'Accept: application/json',
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
} else {
echo $response;
}
curl_close($ch);On Demand Sms
linkid field is required for on demand messages
http
curl -X POST https://app.sharasms.co.ke/api/messages/new/on-demand \
-H "Authorization: Bearer <access_token>" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{
"message": "Hello, this is a test message",
"phone": "2547xxxxxxxx",
"short_code_id": "<short_code_id>",
"linkid": "<linkid>"
}'php
<?php
$url = 'https://app.sharasms.co.ke/api/messages/new/on-demand';
$accessToken = '<access_token>'; // Replace <access_token> with your actual access token
$shortCodeId = '<short_code_id>'; // Replace <short_code_id> with your actual short code ID
$linkid = '<linkid>'; // Replace <linkid> with your actual linkid
$data = [
'message' => 'Hello, this is a test message',
'phone' => '2547xxxxxxxx', // Replace with the actual phone number
'short_code_id' => $shortCodeId,
'linkid' => $linkid,
];
$headers = [
'Authorization: Bearer ' . $accessToken,
'Content-Type: application/json',
'Accept: application/json',
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
} else {
echo $response;
}
curl_close($ch);Sending message to multiple numbers
To send a message to multiple numbers, you can pass an array of phone numbers or send a comma separated string of phone numbers
Using an array of phone numbers
json
{
"message": "Hello, this is a test message",
"phone": ["2547xxxxxxxx", "2547xxxxxxxx"],
"short_code_id": "<short_code_id>"
}Using a comma separated string of phone numbers
json
{
"message": "Hello, this is a test message",
"phone": "2547xxxxxxxx, 2547xxxxxxxx",
"short_code_id": "<short_code_id>"
}