Notifications
client.notifications() is the core of the SDK — building requests, sending them, searching history, and reading delivery receipts.
Anatomy of a request
NotificationRequest is built with a fluent builder. Each channel has a matching to* method that targets the recipient field the API expects for that channel:
| Channel | addChannel value | Recipient method |
|---|---|---|
ChannelType.EMAIL | .toEmail(address) | |
| SMS | ChannelType.SMS | .toPhone(number) |
| Webhook | ChannelType.WEBHOOK | .toWebhook(url) |
| Push (device) | ChannelType.PUSH | .toPushToken(token) |
| Push (topic) | ChannelType.PUSH | .toPushTopic(topic) |
| In-app | ChannelType.IN_APP | .toInApp(userId) |
Two additional builder methods attach rich-media fields shared across channels: .withMediaUrl(imageUrl) and .withActionUrl(actionUrl).
Content can come from either inline fields or a template:
.subject(...)/.message(...)— inline content.templateId(...)+.addVariable(key, value)— rendered from a saved template
.scheduleFor(timestamp) defers delivery to a future time instead of sending immediately.
build() throws if no channel was added via addChannel(...).
Multi-channel requests
A single request can target more than one channel at once — call addChannel multiple times and set the recipient fields for each:
- Java
- Node.js
var request = NotificationRequest.builder()
.addChannel(ChannelType.EMAIL)
.addChannel(ChannelType.SMS)
.toEmail("user@example.com")
.toPhone("+15551234567")
.subject("Order shipped")
.message("Your order is on its way.")
.build();
client.notifications().send(request);
const request = NotificationRequest.builder()
.addChannel(ChannelType.EMAIL)
.addChannel(ChannelType.SMS)
.toEmail('user@example.com')
.toPhone('+15551234567')
.subject('Order shipped')
.message('Your order is on its way.')
.build();
await client.notifications().send(request);
Idempotent sends
Pass your own idempotency key to safely retry a send without risking a duplicate delivery:
- Java
- Node.js
UUID idempotencyKey = UUID.randomUUID();
var response = client.notifications().sendWithIdempotency(request, idempotencyKey);
const idempotencyKey = crypto.randomUUID();
const response = await client.notifications().sendWithIdempotency(request, idempotencyKey);
send(request) is equivalent to calling sendWithIdempotency(request, null).
Bulk sending
- Java
- Node.js
var results = client.notifications().sendBulk(List.of(request1, request2, request3));
const results = await client.notifications().sendBulk([request1, request2, request3]);
Scheduling and cancellation
- Java
- Node.js
var request = NotificationRequest.builder()
.addChannel(ChannelType.EMAIL)
.toEmail("user@example.com")
.subject("Reminder")
.message("Your trial ends tomorrow.")
.scheduleFor(Instant.now().plus(Duration.ofDays(1)))
.build();
var response = client.notifications().send(request);
// Cancel before it fires, using the task id from the response
client.notifications().cancelSchedule(taskId);
const request = NotificationRequest.builder()
.addChannel(ChannelType.EMAIL)
.toEmail('user@example.com')
.subject('Reminder')
.message('Your trial ends tomorrow.')
.scheduleFor(new Date(Date.now() + 24 * 60 * 60 * 1000))
.build();
const response = await client.notifications().send(request);
// Cancel before it fires, using the task id from the response
await client.notifications().cancelSchedule(taskId);
Searching and reading history
- Java
- Node.js
var receipts = client.notifications().search(ChannelType.EMAIL, "DELIVERED", 20, 0);
var one = client.notifications().get(notificationId);
var receiptDetail = client.notifications().getReceipts(notificationId);
const receipts = await client.notifications().search(ChannelType.EMAIL, 'DELIVERED', 20, 0);
const one = await client.notifications().get(notificationId);
const receiptDetail = await client.notifications().getReceipts(notificationId);
search accepts null for channel and status to leave either filter unset.