Skip to main content

Quickstart

This walks through building a client and sending a single email notification.

1. Build a client

import com.notificationhub.sdk.NotificationHubClient;

NotificationHubClient client = new NotificationHubClient.Builder()
.apiKey("your-api-key")
.apiSecret("your-api-secret")
// Optional — defaults to the NotificationHub production endpoint
.baseUrl("your-base-url")
.build();

apiKey and apiSecret are required — the builder throws if either is missing or blank. baseUrl is optional; if provided it must use HTTPS unless the host is localhost.

2. Build a notification request

import com.notificationhub.sdk.model.NotificationRequest;
import com.notificationhub.sdk.model.ChannelType;

NotificationRequest request = NotificationRequest.builder()
.addChannel(ChannelType.EMAIL)
.toEmail("user@example.com")
.subject("Welcome!")
.message("Thanks for signing up.")
.addVariable("firstName", "Ada")
.build();

build() throws if no channel was added — at least one call to addChannel(...) is required.

3. Send it

var response = client.notifications().send(request);

System.out.println(response.notificationId());
System.out.println(response.status());

send(...) returns a NotificationResponse containing the generated notificationId, an idempotencyKey, delivery status, and the list of dispatchedChannels.

What's next