WhatsApp API for Java
Uses java.net.http.HttpClient from Java 11, and a text block from Java 15. No dependency needed. There is no official SDK, just one HTTP request.
Send a message with Java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;
public class SendMessage {
public static void main(String[] args) throws Exception {
String json = """
{"deviceId":1,"to":"923001234567","body":"Hello from QuackAPI"}
""";
HttpRequest request = HttpRequest.newBuilder(URI.create("https://quackapi.com/v1/messages/chat"))
.timeout(Duration.ofSeconds(15))
.header("Content-Type", "application/json")
.header("x-api-key", System.getenv("QUACKAPI_KEY"))
.POST(HttpRequest.BodyPublishers.ofString(json))
.build();
HttpResponse<String> response = HttpClient.newHttpClient()
.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.statusCode() + " " + response.body());
}
}Before you run it
- Connect a device and use its numeric id as deviceId.
- Set QUACKAPI_KEY to your wa_ key.
- Run this on a server. Never ship the key to a browser or app.
Java tips
- Reuse one HttpClient across requests, it is thread safe.
- Use sendAsync when you send many messages so threads are not blocked waiting for responses.
Handling errors
Non-2xx responses carry a JSON message. See the errors page for what each code means and which to retry.
Related
Last reviewed 2026-11-09. QuackAPI is an unofficial linked-device service. Acceptable use