Sending Messages
To ensure successful communication with the API, please include the following headers in all your requests:
Content-Type
: application/jsonAccept
: application/json
The API responses will be returned in the following format:
{
"success": true,
"message": "Message sent successfully",
"data": { }
}
- Javascript
- PHP
- Java
const token = 'YOUR_API_TOKEN';
const baseUrl = 'https://example.com/v2';
const url = `${baseUrl}/send-sms`;
const payload = {
sender_id: 1,
schedule:"none",
sms: "Hello World! I am sending my first SMS message using Notify Africa API",
recipients: [{ number: 2557654321 }, { number: 2557123456 }]
};
const response = await fetch(url, {
method: 'POST',
body: JSON.stringify(payload),
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': `Bearer ${token}`
},
})
<?php
// API endpoint URL
$baseUrl = 'https://example.com/v2';
$url = "$baseUrl/send-sms";
// Data to be sent in the request body
$payload = array(
'sender_id' => 1,
'schedule' => 'none',
'sms' => 'Hello World! I am sending my first SMS message using Notify Africa API',
'recipients' => array(
array('number' => 2557654321),
array('number' => 2557123456)
)
);
// Set the headers and request options
$options = array(
'http' => array(
'header' => "Content-Type: application/json\r\n" .
"Accept: application/json\r\n" .
"Authorization: Bearer YOUR_API_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 "Response: ";
print_r($responseData);
} else {
echo "Error: Unable to send SMS.";
}
?>
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
public class SendSMS {
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,"
+ "\"schedule\": \"none\","
+ "\"sms\": \"Hello World! I am sending my first SMS message using Notify Africa API\","
+ "\"recipients\": [{\"number\": 2557654321}, {\"number\": 2557123456}]"
+ "}";
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 instant messages, value isnone
.