Replace number, type, message, instance id and access token accordingly.
1. Below is the sample code for java:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
public class WhatsAppSender {
public static void main(String[] args) {
String number = "9199XXXXXXXX";
String type = "text";
String message = "test message";
String instanceId = "6616XXXXX";
String accessToken = "661XXXXXX";
try {
String apiUrl = "https://whatsapponcloud.com/api/send" +
"?number=" + URLEncoder.encode(number, "UTF-8") +
"&type=" + URLEncoder.encode(type, "UTF-8") +
"&message=" + URLEncoder.encode(message, "UTF-8") +
"&instance_id=" + URLEncoder.encode(instanceId, "UTF-8") +
"&access_token=" + URLEncoder.encode(accessToken, "UTF-8");
URL url = new URL(apiUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
StringBuilder response = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
response.append(line);
}
reader.close();
System.out.println("API response: " + response.toString());
connection.disconnect();
} catch (IOException e) {
System.err.println("Error sending request: " + e.getMessage());
}
}
}