Integrate WhatsApp Business API with Spring Boot
Send WhatsApp Business messages from any Spring Boot Java application with a single Maven dependency. The Zaptilo Spring Boot starter auto-configures a service bean you can @Autowired anywhere — send text, media, and template messages with one line of code.
Why send WhatsApp from Spring Boot?
Spring Boot powers most modern Java backends — from order management to fintech platforms. Instead of writing raw HTTP client code, the Zaptilo starter gives you a typed, auto-configured service that follows Spring conventions.
- Drop-in Maven or Gradle dependency — no manual bean wiring
- Auto-configured Spring bean built on
RestTemplate - Send text, media (image/video/document), and approved template messages
- Compatible with Spring Boot 2.x and 3.x, Java 17+
- Zero external HTTP libraries — uses what your app already has
Prerequisites
- Java 17 or higher
- Spring Boot 2.x or 3.x application
- A free Zaptilo account with an API token (Dashboard → Developer Tools → Access Tokens)
- An approved WhatsApp template in your Zaptilo account (for template messages)
Step 1: Add the Maven Dependency
Add the Zaptilo WhatsApp starter to your pom.xml:
<dependency>
<groupId>ai.zaptilo</groupId>
<artifactId>zaptilo-whatsapp-spring-boot-starter</artifactId>
<version>1.0.0</version>
</dependency>Or with Gradle in build.gradle:
implementation 'ai.zaptilo:zaptilo-whatsapp-spring-boot-starter:1.0.0'Step 2: Configure Your API Token
Add your Zaptilo API token to application.properties:
zaptilo.api.token=your_token_here
zaptilo.api.base-url=https://web.zaptilo.aiOr in application.yml:
zaptilo:
api:
token: your_token_here
base-url: https://web.zaptilo.aiStep 3: Inject and Send Messages
Inject ZaptiloWhatsAppService into any Spring component:
import ai.zaptilo.whatsapp.ZaptiloWhatsAppService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class NotificationService {
@Autowired
private ZaptiloWhatsAppService whatsApp;
public void sendOrderConfirmation(String customerNumber, String orderId) {
whatsApp.sendTemplate(
customerNumber,
"order_confirmation",
"en",
List.of("John Doe", orderId),
null
);
}
public void sendWelcomeText(String number) {
whatsApp.sendMessage(number, "Welcome to our service!");
}
public void sendInvoice(String number, String invoiceUrl) {
whatsApp.sendMedia(number, invoiceUrl, "document", "Your invoice");
}
}Step 4: Send from a REST Controller
Trigger a WhatsApp message from any HTTP endpoint — perfect for webhooks and order events:
@RestController
public class WebhookController {
@Autowired
private ZaptiloWhatsAppService whatsApp;
@PostMapping("/order-placed")
public ResponseEntity<?> onOrderPlaced(@RequestBody Order order) {
whatsApp.sendTemplate(
order.getCustomerPhone(),
"order_confirmation",
"en",
List.of(order.getCustomerName(), order.getId()),
null
);
return ResponseEntity.ok().build();
}
}API Reference
| Method | Description |
|---|---|
| sendMessage(number, message) | Send a plain text message |
| sendMedia(number, mediaUrl, mediaType, caption) | Send image, video, or document |
| sendTemplate(number, templateName, language, bodyValues, headerValues) | Send an approved template message |
| getTemplates() | List all approved templates |
| getBalance() | Get current credit balance |
| verify() | Verify API token and subscription |
Error Handling
Wrap calls in try/catch to handle API failures gracefully:
try {
whatsApp.sendMessage("919876543210", "Hello!");
} catch (HttpClientErrorException e) {
log.error("Zaptilo API error: {}", e.getResponseBodyAsString());
}Common Use Cases
Order Confirmations
Send instant order receipts from your @PostMapping order endpoint.
OTP Delivery
Trigger one-time passwords from your authentication service.
Payment Receipts
Send WhatsApp receipts after a Razorpay or Stripe webhook.
Shipment Updates
Notify customers from your logistics microservice when tracking changes.
Appointment Reminders
Schedule reminders with @Scheduled jobs in Spring Boot.
System Alerts
Notify on-call engineers when health check thresholds are crossed.
Best Practices
- Store your API token in environment variables or Spring Cloud Config — never commit to source control.
- Use
@Asyncfor high-volume sends so message delivery does not block your request thread. - Wrap WhatsApp calls in a circuit breaker (Resilience4j) for production resilience.
- Log responses to your standard SLF4J logger for observability.
- Use template messages for any message sent outside the 24-hour customer service window.
Frequently asked questions
How do I add the Zaptilo Spring Boot starter to my project?
Add the Maven dependency `ai.zaptilo:zaptilo-whatsapp-spring-boot-starter:1.0.0` (or the equivalent Gradle line) to your build file. The starter auto-configures a ZaptiloWhatsAppService bean which you can @Autowired anywhere.
Does the Zaptilo starter work with Spring Boot 2 and Spring Boot 3?
Yes. The starter is compatible with both Spring Boot 2.x and 3.x and requires Java 17 or higher. It uses RestTemplate from spring-boot-starter-web.
How do I configure the API token in Spring Boot?
Add `zaptilo.api.token=your_token` and `zaptilo.api.base-url=https://web.zaptilo.ai` to application.properties (or the YAML equivalent). The starter reads these values via @Value injection.
What is the cost of the Spring Boot WhatsApp Business API for India?
Zaptilo charges per message starting from ₹0.04 at volume, billed in INR with a GST invoice. There is no monthly subscription, no setup fee, and no per-user fee — making it the most cost-effective WhatsApp Business API for Indian Spring Boot teams.
Get your Zaptilo API token
Sign up free, generate your API token, and start sending WhatsApp messages from Spring Boot in minutes. No subscription, pay only for what you use.
Get Started FreeSee also: All Integrations · Laravel · Node.js · .NET · API Reference