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:
Map<String, Object> payload = new HashMap<>();
payload.put("customVariables", "Hello");
Map<String, Object> to = new HashMap<>();
to.put("subscriberId", "<SUBSCRIBER_IDENTIFIER_FROM_ADMIN_PANEL>");
to.put("phone", "07983882186");
Map<String, Object> event = new HashMap<>();
event.put("name", "<REPLACE_WITH_TEMPLATE_NAME_FROM_ADMIN_PANEL>");
event.put("payload", payload);
event.put("to", to);
// Call a method to perform trigger event with 'event' map
// Example method:
triggerEvent(event);
Bulk Trigger events:
List<Map<String, Object>> events = new ArrayList<>();
// First event
Map<String, Object> event1 = new HashMap<>();
event1.put("name", "<REPLACE_WITH_TEMPLATE_NAME_FROM_ADMIN_PANEL>");
event1.put("to", "<SUBSCRIBER_IDENTIFIER_FROM_ADMIN_PANEL>");
Map<String, Object> payload1 = new HashMap<>();
payload1.put("customVariables", "Hello");
event1.put("payload", payload1);
events.add(event1);
// Second event
Map<String, Object> event2 = new HashMap<>();
event2.put("name", "<REPLACE_WITH_TEMPLATE_NAME_FROM_ADMIN_PANEL>");
event2.put("to", "<SUBSCRIBER_IDENTIFIER_FROM_ADMIN_PANEL>");
Map<String, Object> payload2 = new HashMap<>();
payload2.put("customVariables", "World");
event2.put("payload", payload2);
events.add(event2);
// Third event
Map<String, Object> event3 = new HashMap<>();
event3.put("name", "<REPLACE_WITH_TEMPLATE_NAME_FROM_ADMIN_PANEL>");
event3.put("to", "<SUBSCRIBER_IDENTIFIER_FROM_ADMIN_PANEL>");
Map<String, Object> payload3 = new HashMap<>();
payload3.put("customVariables", "Again");
event3.put("payload", payload3);
events.add(event3);
// Call a method to perform bulk trigger with 'events' list
// Example method:
bulkTriggerEvent(events);
Broadcast event to all existing subscribers:
Map<String, Object> payload = new HashMap<>();
payload.put("customVariables", "Hello");
Map<String, Object> event = new HashMap<>();
event.put("name", "<REPLACE_WITH_EVENT_NAME_FROM_ADMIN_PANEL>");
event.put("payload", payload);
event.put("transactionId", "<REPLACE_WITH_TRANSACTION_ID>");
// Call a method to perform broadcast event with 'event' map
// Example method:
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 a method to cancel event using the 'transactionId'
// Example method:
cancelTriggeredEvent(transactionId);
// Create subscriber & get the details of the recently created subscriber returned.
Map<String, Object> subscriber = new HashMap<>();
subscriber.put("subscriberId", "YOUR_SYSTEM_USER_ID");
subscriber.put("email", "<insert-email>");
subscriber.put("firstName", "<insert-firstname>");
subscriber.put("lastName", "<insert-lastname>");
subscriber.put("phone", "<insert-phone>");
subscriber.put("avatar", "<insert-avatar>");
// Call a method to create a subscriber with the 'subscriber' map
// Example method:
createSubscriber(subscriber);
// Get subscriber
String subscriberId = "<YOUR_SUBSCRIBER_ID>"; // Replace with the actual subscriber ID
// Call a method to get the subscriber using 'subscriberId'
// Example method:
getSubscriber(subscriberId);
// Update subscriber
Map<String, Object> updatedFields = new HashMap<>();
updatedFields.put("email", "<insert-email>");
updatedFields.put("firstName", "<insert-firstname>");
updatedFields.put("lastName", "<insert-lastname>");
updatedFields.put("phone", "<insert-phone>");
updatedFields.put("avatar", "<insert-avatar>");
// Call a method to update the subscriber with 'subscriberId' and 'updatedFields' map
// Example method:
updateSubscriber(subscriberId, updatedFields);
// Delete subscriber
String subscriberId = "<YOUR_SUBSCRIBER_ID>"; // Replace with the actual subscriber ID
// Call a method to delete the subscriber using 'subscriberId'
// Example method:
deleteSubscriber(subscriberId);
// Update subscriber credentials
String subscriberId = "<YOUR_SUBSCRIBER_ID>"; // Replace with the actual subscriber ID
Map<String, Object> credentialsUpdate = new HashMap<>();
credentialsUpdate.put("providerId", "<insert-providerId>");
credentialsUpdate.put("credentials", "<insert-credentials>");
// Call a method to update subscriber credentials with 'subscriberId' and 'credentialsUpdate' map
// Example method:
updateSubscriberCredentials(subscriberId, credentialsUpdate);
// Update subscriber online status
String subscriberId = "<YOUR_SUBSCRIBER_ID>"; // Replace with the actual subscriber ID
boolean isOnlineStatus = true; // Set to true or false
// Call a method to update subscriber online status with 'subscriberId' and 'isOnlineStatus'
// Example method:
updateSubscriberOnlineStatus(subscriberId, isOnlineStatus);
// Get subscriber preferences
String subscriberId = "<YOUR_SUBSCRIBER_ID>"; // Replace with the actual subscriber ID
// Call a method to get subscriber preferences using 'subscriberId'
// Example method:
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
Map<String, Object> preferenceUpdate = new HashMap<>();
preferenceUpdate.put("channel", "<insert-channel>");
preferenceUpdate.put("enabled", "<insert-boolean-value>"); // Set to true or false, optional
// Call a method to update subscriber preference using 'subscriberId', 'templateId', and 'preferenceUpdate' map
// Example method:
updateSubscriberPreference(subscriberId, templateId, preferenceUpdate);
// Get a notification feed for a particular subscriber
String subscriberId = "<YOUR_SUBSCRIBER_ID>"; // Replace with the actual subscriber ID
// Call a method to get the notification feed for subscriber using 'subscriberId'
// Example method:
getSubscriberNotificationsFeed(subscriberId);
// Get the unseen notification count for subscribers feed
String subscriberId = "<YOUR_SUBSCRIBER_ID>"; // Replace with the actual subscriber ID
// Call a method to get the unseen notification count for subscriber using 'subscriberId'
// Example method:
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
Map<String, Object> request = new HashMap<>();
//request
// Call a method to mark a subscriber's feed message as seen using 'subscriberId', 'messageId', and 'options' map
// Example method:
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
Map<String, Object> request = new HashMap<>();
//request
// Call a method to mark a subscriber's message action as seen using 'subscriberId', 'messageId', 'type', and 'options' map
// Example method:
markMessageActionAsSeen(subscriberId, messageId, type, request);
// Create a Topic
Map<String, Object> topic = new HashMap<>();
topic.put("key", key);
topic.put("name", name);
// Call a method to create a topic with 'key' and 'name'
// Example method:
createTopic(topic);
// Fetch all topics
// Call a method to get the topics list
// Example method:
filterTopics();
// Get a topic
String topickey = "topicKey"; // Replace with the actual subscriber ID
// Call a method to get the topic using 'topickey'
// Example method:
getTopic(topickey);
// Add subscribers to a topic
String topicKey = "<YOUR_TOPIC_KEY>";
List<String> subscribers = new ArrayList<>();
// subscribers request
// Call a method to add subscribers to a topic using 'topicKey' and 'subscribers' list
// Example method:
addSubscribersToTopic(topicKey, subscribers);
// Remove subscribers from a topic
String topicKey = "<YOUR_TOPIC_KEY>"; // Replace with the actual topic key
List<String> subscribers = new ArrayList<>();
// subscribers request
// Call a method to remove subscribers from a topic using 'topicKey' and 'subscribers' list
// Example method:
removeSubscribersFromTopic(topicKey, subscribers);
// Rename a topic
String topicKey = "<YOUR_TOPIC_KEY>"; // Replace with the actual topic key
Map<String, Object> topic = new HashMap<>();
topic.put("name", name);
// Call a method to rename a topic using 'topicKey' and 'topic'
// Example method:
renameTopic(topicKey, topic);
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.