Schedule Messages
To ensure successful communication with the API, please include the following headers in all your requests:
Content-Type
: application/jsonAccept
: application/json
In addition to the previous process, there are few parameters that may change on the request body; startTime
,
startDate
, endDate
, and scheduledOption
.
To ensure successful communication with the API, please include the following headers in all your requests:
The API responses will be returned in the following format:
{
"success": true,
"message": "Message sent successfully",
"data": { }
}
- Javascript
- PHP
- Java
const baseUrl = 'https://example.com/v2';
const url = `${baseUrl}/send-sms`
const token = `Your token from profile page`
// Define the payload for the API request
const payload = {
sender_id: 1,
sms: "Hello World! I am scheduling my first SMS message using Notify Africa API for 2 days every 8:27 AM",
schedule:"daily", //scheduled options "none","daily", "weekly", "monthly"
start_date:"2024-10-23", // year-month-date
end_date:"2024-10-25", //year-month-date
time:'8:27',
recipients: [{ number: 25571234567 }, { number: 25571234567 }]
};
// Make the API request using the fetch function
const response = await fetch(apiUrl, {
method: 'POST',
body: JSON.stringify(payload),
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': `Bearer ${token}`
}
});
// Handle the response from the API
if (response.ok) {
const data = await response.json();
console.log("API response:", data);
} else {
console.error("API request failed with status:", response.status);
}
<?php
$baseUrl = 'https://example.com/v2';
$url = "$baseUrl/send-sms";
$token = 'Your token from profile page';
// Define the payload for the API request
$payload = array(
'sender_id' => 1,
'sms' => "Hello World! I am scheduling my first SMS message using Notify Africa API for 2 days every 8:27 AM",
'schedule' => "daily", // scheduled options "none", "daily", "weekly", "monthly"
'start_date' => "2024-10-23", // year-month-date
'end_date' => "2024-10-25", // year-month-date
'time' => '8:27',
'recipients' => array(
array('number' => 25571234567),
array('number' => 25571234567)
)
);
// Set the headers and request options
$options = array(
'http' => array(
'header' => "Content-Type: application/json\r\n" .
"Accept: application/json\r\n" .
"Authorization: Bearer $token\r\n",
'method' => 'POST',
'content' => json_encode($payload)
)
);
// Create a stream context
$context = stream_context_create($options);
// Send the request and get the response
$response = file_get_contents($url, false, $context);
// Parse the response JSON
$responseData = json_decode($response, true);
// Check if the response is successful
if ($response !== false) {
echo "API response: ";
print_r($responseData);
} else {
echo "API request failed with status: " . $http_response_header[0];
}
?>
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
public class ScheduleSMS {
public static void main(String[] args) {
String token = "YOUR_API_TOKEN";
String baseUrl = "https://example.com/v2";
String url = baseUrl + "/send-sms";
String payload = "{"
+ "\"sender_id\": 1,"
+ "\"sms\": \"Hello World! I am scheduling my first SMS message using Notify Africa API for 2 days every 8:27 AM\","
+ "\"schedule\": \"daily\","
+ "\"start_date\": \"2024-10-23\","
+ "\"end_date\": \"2024-10-25\","
+ "\"time\": \"8:27\","
+ "\"recipients\": [{\"number\": 25571234567}, {\"number\": 25571234567}]"
+ "}";
try {
URL apiUrl = new URL(url);
HttpURLConnection conn = (HttpURLConnection) apiUrl.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("Accept", "application/json");
conn.setRequestProperty("Authorization", "Bearer " + token);
conn.setDoOutput(true);
// Write the request body
OutputStream outputStream = conn.getOutputStream();
outputStream.write(payload.getBytes());
outputStream.flush();
// Get the response code
int responseCode = conn.getResponseCode();
// Read the response body
BufferedReader reader;
if (responseCode == HttpURLConnection.HTTP_OK) {
reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
} else {
reader = new BufferedReader(new InputStreamReader(conn.getErrorStream()));
}
StringBuilder response = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
response.append(line);
}
reader.close();
// Check if the request was successful
if (responseCode == HttpURLConnection.HTTP_OK) {
System.out.println("Response: " + response.toString());
} else {
System.out.println("Error: " + response.toString());
}
// Close the connection
conn.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Request Parameters
The following parameters are required when sending an SMS message:
sender_id
: The ID of the sender. This can be obtained from the sender ID list.schedule
: The schedule for sending the message. For schedules available values aredaily
,weekly
, andmonthly
.start_date
: The date to start sending the message. The format isYYYY-MM-DD
.end_date
: The date to stop sending the message. The format isYYYY-MM-DD
.time
: The time to send the message. The format isHH:MM
.recipients
: An array of recipient objects containing thenumber
field. The recipient's phone number should be in international format (e.g., 25571234567).sms
: The message to be sent. The message should not exceed 160 characters for a single SMS. For longer messages, use concatenation or Unicode encoding.token
: The API token used to authenticate the request.Content-Type
: The content type of the request. Set this toapplication/json
.Accept
: The expected response format. Set this toapplication/json
.