The Novu Java SDK provides a fluent and expressive interface for interacting with Novu's API and managing notifications. Please refer to the full documentation to learn more.
Maven users:
<!--add dependency-->
<dependency>
<groupId>co.novu</groupId>
<artifactId>novu-java</artifactId>
<version>1.6.0</version>
</dependency>
Gradle users:
// add dependency
dependencies {
implementation 'co.novu:novu-java:1.6.0'
}
Sync your project, and you should have the artifacts downloaded.
First, create an instance of the Novu SDK like so:
import co.novu.sdk.Novu;
public class Main {
public static void main(String[] args) {
String apiKey = "INSERT_API_KEY_HERE";
// Using the API Key only
Novu novu = new Novu(apiKey);
// Using the Config Param
NovuConfig novuConfig = new NovuConfig(apiKey);
Novu novu = new Novu(novuConfig);
// Sample usage
novu.triggerEvent(event);
}
}
// Sign up on https://web.novu.co and grab your API key from https://web.novu.co/settings
Trigger an event - send notification to subscribers:
TriggerEventRequest event = new TriggerEventRequest();
event.setName("name");
SubscriberRequest subscriberRequest = new SubscriberRequest();
subscriberRequest.setFirstName("fName");
subscriberRequest.setLastName("lName");
subscriberRequest.setEmail("[email protected]");
subscriberRequest.setSubscriberId("subId");
Map<String, Object> payload = new HashMap<>();
payload.put("customVariables", "Hello");
event.setTo(subscriberRequest);
event.setPayload(payload);
event.setActor("actor");
event.setTenant("tenant");
// Call the method to perform trigger event with 'event' request
novu.triggerEvent(event);
Bulk Trigger events:
List<TriggerEventRequest> events = new ArrayList<>();
// First event
TriggerEventRequest event1 = new TriggerEventRequest();
event1.setName("name");
SubscriberRequest subscriberRequest = new SubscriberRequest();
subscriberRequest.setFirstName("fName");
subscriberRequest.setLastName("lName");
subscriberRequest.setEmail("[email protected]");
subscriberRequest.setSubscriberId("subId");
Map<String, Object> payload = new HashMap<>();
payload.put("customVariables", "Hello");
event1.setTo(subscriberRequest);
event1.setPayload(payload);
event1.setActor("actor");
event1.setTenant("tenant");
events.add(event1);
// Second event
TriggerEventRequest event2 = new TriggerEventRequest();
event2.setName("name");
SubscriberRequest subscriberRequest = new SubscriberRequest();
subscriberRequest.setFirstName("fName");
subscriberRequest.setLastName("lName");
subscriberRequest.setEmail("[email protected]");
subscriberRequest.setSubscriberId("subId");
Map<String, Object> payload = new HashMap<>();
payload.put("customVariables", "Hello");
event2.setTo(subscriberRequest);
event2.setPayload(payload);
event2.setActor("actor");
event2.setTenant("tenant");
events.add(event2);
BulkTriggerEventRequest bulkEventRequest = new BulkTriggerEventRequest();
bulkTriggerEventRequest.setEvents(events);
// Call the method to perform bulk trigger with the request body
novu.bulkTriggerEvent(bulkEventRequest);
Broadcast event to all existing subscribers:
TriggerEventRequest event = new TriggerEventRequest();
event.setName("name");
SubscriberRequest subscriberRequest = new SubscriberRequest();
subscriberRequest.setFirstName("fName");
subscriberRequest.setLastName("lName");
subscriberRequest.setEmail("[email protected]");
subscriberRequest.setSubscriberId("subId");
Map<String, Object> payload = new HashMap<>();
payload.put("customVariables", "Hello");
event.setTo(subscriberRequest);
event.setPayload(payload);
event.setActor("actor");
event.setTenant("tenant");
// Call the method to perform broadcast event with the request body
novu.broadcastEvent(event);
Cancel triggered event. Using a previously generated transactionId during the event trigger, this action will cancel any active or pending workflows:
String transactionId = "<REPLACE_WITH_TRANSACTION_ID>";
// Call the method to cancel event using the 'transactionId'
novu.cancelTriggeredEvent(transactionId);
//=== Create subscriber & get the details of the recently created subscriber returned. ===//
SubscriberRequest subscriber = new SubscriberRequest();
subscriber.setFirstName("fName");
subscriber.setLastName("lName");
subscriber.setEmail("[email protected]");
// Call the method to create a subscriber with the 'subscriber' request
novu.createSubscriber(subscriber);
//=== Get subscriber ===//
String subscriberId = "<YOUR_SUBSCRIBER_ID>"; // Replace with the actual subscriber ID
// Call the method to get the subscriber using 'subscriberId'
novu.getSubscriber(subscriberId);
//=== Update subscriber ===//
UpdateSubscriberRequest request = new UpdateSubscriberRequest();
request.setFirstName("name");
request.setLastName("lName");
// Add other fields
// Call the method to update the subscriber with the request body and the subscriber's ID
novu.updateSubscriber(request, subscriberId);
//=== Delete subscriber ===//
String subscriberId = "<YOUR_SUBSCRIBER_ID>"; // Replace with the actual subscriber ID
// Call the method to delete the subscriber using their 'subscriberId'
novu.deleteSubscriber(subscriberId);
//=== Update subscriber credentials ===//
String subscriberId = "<YOUR_SUBSCRIBER_ID>"; // Replace with the actual subscriber ID
UpdateSubscriberCredentialsRequest request = new UpdateSubscriberCredentialsRequest();
request.setProviderId("pId");
// Add other fields
// Call the method to update subscriber credentials with the request body and the subscriber's ID
novu.updateSubscriberCredentials(request, subscriberId);
//=== Update subscriber online status ===//
String subscriberId = "<YOUR_SUBSCRIBER_ID>"; // Replace with the actual subscriber ID
UpdateSubscriberOnlineStatusRequest request = new UpdateSubscriberOnlineStatusRequest();
request.setIsOnline(true); // Set to true or false
// Call the method to update subscriber online status with the request body and the subscriber's ID
novu.updateSubscriberOnlineStatus(request, subscriberId);
//=== Get subscriber preferences ===//
String subscriberId = "<YOUR_SUBSCRIBER_ID>"; // Replace with the actual subscriber ID
// Call the method to get a subscriber's preferences using 'subscriberId'
novu.getSubscriberPreferences(subscriberId);
//=== Update subscriber preference ===//
String subscriberId = "<YOUR_SUBSCRIBER_ID>"; // Replace with the actual subscriber ID
String templateId = "<INSERT_TEMPLATE_ID>"; // Replace with the actual template ID
UpdateSubscriberPreferenceRequest request = new UpdateSubscriberPreferenceRequest();
request.setEnabled(false); // Set to true or false, optional
// Call the method to update subscriber preferences with the request body, 'subscriberId', and 'templateId'
novu.updateSubscriberPreference(request, subscriberId, templateId);
//=== Get a notification feed for a particular subscriber ===//
String subscriberId = "<YOUR_SUBSCRIBER_ID>"; // Replace with the actual subscriber ID
// Call the method to get the notification feed for a subscriber using 'subscriberId'
novu.getSubscriberNotificationsFeed(subscriberId);
//=== Get the unseen notification count for subscribers feed ===//
String subscriberId = "<YOUR_SUBSCRIBER_ID>"; // Replace with the actual subscriber ID
// Call the method to get the unseen notification count for subscriber using 'subscriberId'
novu.getSubscriberUnseenNotificationsCount(subscriberId);
//=== Mark a subscriber feed message as seen ===//
String subscriberId = "<YOUR_SUBSCRIBER_ID>"; // Replace with the actual subscriber ID
String messageId = "<YOUR_MESSAGE_ID>"; // Replace with the actual message ID
MarkSubscriberFeedAsRequest request = new MarkSubscriberFeedAsRequest();
Mark mark = new Mark();
mark.setRead(true);
mark.setSeen(true);
request.setMark(mark);
request.setMessageId(messageId);
// Call the method to mark a subscriber's feed message as seen using the request body and 'subscriberId'
novu.markSubscriberMessageFeedAs(subscriberId, messageId, request);
//=== Mark message action as seen ===//
String subscriberId = "<YOUR_SUBSCRIBER_ID>"; // Replace with the actual subscriber ID
String messageId = "<YOUR_MESSAGE_ID>"; // Replace with the actual message ID
String type = "<YOUR_ACTION_TYPE>"; // Replace with the actual action type
MarkMessageActionAsSeenRequest request = new MarkMessageActionAsSeenRequest();
request.setStatus("read");
// Call the method to mark a subscriber's message action as seen using the request body, 'subscriberId', 'messageId' and 'type'
novu.markMessageActionAsSeen(request, subscriberId, messageId, type);
//=== Create a Topic ===//
TopicRequest topicRequest = new TopicRequest();
topicRequest.setKey("key");
topicRequest.setName("name");
// Call the method to create a topic with the request body
novu.createTopic(topicRequest);
//=== Fetch all Topics ===//
FilterTopicsRequest topicsRequest = new FilterTopicsRequest();
topicsRequest.setPage(1);
topicsRequest.setPageSize(10);
topicsRequest.setKey("key");
// Call the method to get the Topics list
novu.filterTopics(topicsRequest);
//=== Get a Topic ===//
String topickey = "<YOUR_TOPIC_KEY>"; // Replace with the actual Topic key
// Call the method to get a Topic using the 'topickey'
novu.getTopic(topickey);
//=== Add subscribers to a Topic ===//
String topicKey = "<YOUR_TOPIC_KEY>"; // Replace with the actual Topic key
List<String> subscribers = new ArrayList<>();
subscribers.add("<SUBSCRIBER_ID>");
SubscriberAdditionRequest additionRequest = new SubscriberAdditionRequest();
additionRequest.setSubscribers(subscribers);
// Call the method to add subscribers to a Topic using the request body and 'topicKey'
novu.addSubscribersToTopic(additionRequest, topicKey);
//=== Remove subscribers from a Topic ===//
String topicKey = "<YOUR_TOPIC_KEY>"; // Replace with the actual topic key
List<String> subscribers = new ArrayList<>();
subscribers.add("<SUBSCRIBER_ID>");
SubscriberAdditionRequest request = new SubscriberAdditionRequest();
request.setSubscribers(subscribers);
// Call the method to remove subscribers from a Topic using the request body and 'topicKey'
novu.removeSubscribersFromTopic(request, topicKey);
//=== Rename a Topic ===//
String topicKey = "<YOUR_TOPIC_KEY>"; // Replace with the actual topic key
RenameTopicRequest renameTopicRequest = new RenameTopicRequest();
renameTopicRequest.setName("name");
// Call the method to rename a Topic using the request body and 'topicKey'
novu.renameTopic(renameTopicRequest, topicKey);
changes(query = {})
countChanges()
applyBulkChanges()
applyChange(changeId)
currentEnvironment()
createEnvironment(body)
environments()
updateEnvironment(environmentId, body)
apiKeys()
regenerateApiKeys()
updateWidgetSettings(body)
executionDetails(query = {})
createFeed(body)
feeds()
deleteFeed(feedId)
validateMxRecordSetupForInboundParse()
integrations()
createIntegration(body)
activeIntegrations()
webhookProviderStatus(providerId)
updateIntegration(integrationId, body)
deleteIntegration(integrationId)
channelLimit(channelType)
inAppStatus()
setIntegrationAsPrimary(integrationId)
createLayout(body)
layouts(query = {})
layout(layoutId)
deleteLayout(layoutId)
updateLayout(layoutId, body)
makeDefaultLayout(layoutId)
messages(query = {})
deleteMessage(messageId)
createWorkflowGroup(body)
notificationGroups()
updateWorkflowGroup(workflowId, body)
notificationTemplates(query = {})
createWorkflow(body)
updateWorkflow(WorkflowId, body)
deleteWorkflow(WorkflowId)
Workflow(WorkflowId)
updateWorkflowStatus(WorkflowId, body)
createWorkflowOverride(createWorkflowOverrideRequest)
getWorkflowOverrides(getWorkflowOverrideRequest)
getWorkflowOverride(workflowId, tenantId)
getWorkflowOverrideById(overrideId)
updateWorkflowOverride(workflowId, tenantId)
updateWorkflowOverrideById(overrideId)
deleteWorkflowOverride(overrideId)
notifications(query = {})
notificationsStats()
notificationsGraphStats(query = {})
notification(notificationId)
getBlueprintsByCategory()
getBlueprint(templateId)
getTenants(body)
createTenant(body)
getTenant(identifier)
updateTenant(body, identifier)
deleteTenant(identifier)
For more information about these methods and their parameters, see the API documentation.
Feature requests, bug reports and pull requests are welcome. Please create an issue.
Be sure to visit the Novu official documentation website for additional information about our API. If you need additional assistance, join our Discord server here.
Novu Java SDK is licensed under the MIT License - see the LICENSE file for details.