Quickstart
This walks through building a client and sending a single email notification.
1. Build a client
- Java
- Node.js
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();
import { NotificationHubClient } from '@sumitshresht/notificationhub-sdk';
const 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
- Java
- Node.js
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();
import { NotificationRequest, ChannelType } from '@sumitshresht/notificationhub-sdk';
const 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
- Java
- Node.js
var response = client.notifications().send(request);
System.out.println(response.notificationId());
System.out.println(response.status());
const response = await client.notifications().send(request);
console.log(response.notificationId);
console.log(response.status);
send(...) returns a NotificationResponse containing the generated notificationId, an idempotencyKey, delivery status, and the list of dispatchedChannels.
What's next
- Send to multiple channels at once — see Notifications
- Reuse a saved template instead of inline
subject/message— see Templates - Handle failures — see Error Handling