Topics are a way to group subscribers together so that they can be notified of events at once. A topic is identified by a custom key. This can be helpful for things like sending out marketing emails or notifying users of new features. Topics can also be used to send notifications to the subscribers who have been grouped together based on their interests, location, activities and much more. https://docs.novu.co/subscribers/topics
- fetchAll - List all topics
- upsert - Create a topic
- get - Retrieve a topic
- modify - Update a topic
- remove - Delete a topic
- createSubscription - Create topic subscriptions
- getSubscriptionById - Retrieve a topic subscription
This api returns a paginated list of topics. Topics can be filtered by key, name, or includeCursor to paginate through the list. Checkout all available filters in the query section.
package hello.world;
import co.novu.Novu;
import co.novu.models.errors.ErrorDto;
import co.novu.models.errors.ValidationErrorDto;
import co.novu.models.operations.TopicsControllerListTopicsRequest;
import co.novu.models.operations.TopicsControllerListTopicsResponse;
import java.lang.Exception;
public class Application {
public static void main(String[] args) throws ErrorDto, ValidationErrorDto, Exception {
Novu sdk = Novu.builder()
.secretKey("YOUR_SECRET_KEY_HERE")
.build();
TopicsControllerListTopicsRequest req = TopicsControllerListTopicsRequest.builder()
.limit(10d)
.build();
TopicsControllerListTopicsResponse res = sdk.topics().fetchAll()
.request(req)
.call();
if (res.listTopicsResponseDto().isPresent()) {
System.out.println(res.listTopicsResponseDto().get());
}
}
}| Parameter | Type | Required | Description |
|---|---|---|---|
request |
TopicsControllerListTopicsRequest | ✔️ | The request object to use for the request. |
TopicsControllerListTopicsResponse
| Error Type | Status Code | Content Type |
|---|---|---|
| models/errors/ErrorDto | 414 | application/json |
| models/errors/ErrorDto | 400, 401, 403, 404, 405, 409, 413, 415 | application/json |
| models/errors/ValidationErrorDto | 422 | application/json |
| models/errors/ErrorDto | 500 | application/json |
| models/errors/APIException | 4XX, 5XX | */* |
Creates a new topic if it does not exist, or updates an existing topic if it already exists. Use ?failIfExists=true to prevent updates.
package hello.world;
import co.novu.Novu;
import co.novu.models.components.CreateUpdateTopicRequestDto;
import co.novu.models.errors.*;
import co.novu.models.operations.TopicsControllerUpsertTopicResponse;
import java.lang.Exception;
public class Application {
public static void main(String[] args) throws TopicResponseDtoException, ErrorDto, ValidationErrorDto, Exception {
Novu sdk = Novu.builder()
.secretKey("YOUR_SECRET_KEY_HERE")
.build();
TopicsControllerUpsertTopicResponse res = sdk.topics().upsert()
.body(CreateUpdateTopicRequestDto.builder()
.key("task:12345")
.name("Task Title")
.build())
.call();
if (res.topicResponseDto().isPresent()) {
System.out.println(res.topicResponseDto().get());
}
}
}| Parameter | Type | Required | Description |
|---|---|---|---|
failIfExists |
Optional<Boolean> | ➖ | If true, the request will fail if a topic with the same key already exists |
idempotencyKey |
Optional<String> | ➖ | A header for idempotency purposes |
body |
CreateUpdateTopicRequestDto | ✔️ | N/A |
TopicsControllerUpsertTopicResponse
| Error Type | Status Code | Content Type |
|---|---|---|
| models/errors/TopicResponseDtoException | 409 | application/json |
| models/errors/ErrorDto | 414 | application/json |
| models/errors/ErrorDto | 400, 401, 403, 404, 405, 413, 415 | application/json |
| models/errors/ValidationErrorDto | 422 | application/json |
| models/errors/ErrorDto | 500 | application/json |
| models/errors/APIException | 4XX, 5XX | */* |
Retrieve a topic by its unique key identifier topicKey
package hello.world;
import co.novu.Novu;
import co.novu.models.errors.ErrorDto;
import co.novu.models.errors.ValidationErrorDto;
import co.novu.models.operations.TopicsControllerGetTopicResponse;
import java.lang.Exception;
public class Application {
public static void main(String[] args) throws ErrorDto, ValidationErrorDto, Exception {
Novu sdk = Novu.builder()
.secretKey("YOUR_SECRET_KEY_HERE")
.build();
TopicsControllerGetTopicResponse res = sdk.topics().get()
.topicKey("<value>")
.call();
if (res.topicResponseDto().isPresent()) {
System.out.println(res.topicResponseDto().get());
}
}
}| Parameter | Type | Required | Description |
|---|---|---|---|
topicKey |
String | ✔️ | The key identifier of the topic |
idempotencyKey |
Optional<String> | ➖ | A header for idempotency purposes |
TopicsControllerGetTopicResponse
| Error Type | Status Code | Content Type |
|---|---|---|
| models/errors/ErrorDto | 414 | application/json |
| models/errors/ErrorDto | 400, 401, 403, 404, 405, 409, 413, 415 | application/json |
| models/errors/ValidationErrorDto | 422 | application/json |
| models/errors/ErrorDto | 500 | application/json |
| models/errors/APIException | 4XX, 5XX | */* |
Update a topic name by its unique key identifier topicKey
package hello.world;
import co.novu.Novu;
import co.novu.models.components.UpdateTopicRequestDto;
import co.novu.models.errors.ErrorDto;
import co.novu.models.errors.ValidationErrorDto;
import co.novu.models.operations.TopicsControllerUpdateTopicResponse;
import java.lang.Exception;
public class Application {
public static void main(String[] args) throws ErrorDto, ValidationErrorDto, Exception {
Novu sdk = Novu.builder()
.secretKey("YOUR_SECRET_KEY_HERE")
.build();
TopicsControllerUpdateTopicResponse res = sdk.topics().modify()
.topicKey("<value>")
.body(UpdateTopicRequestDto.builder()
.name("Updated Topic Name")
.build())
.call();
if (res.topicResponseDto().isPresent()) {
System.out.println(res.topicResponseDto().get());
}
}
}| Parameter | Type | Required | Description |
|---|---|---|---|
topicKey |
String | ✔️ | The key identifier of the topic |
idempotencyKey |
Optional<String> | ➖ | A header for idempotency purposes |
body |
UpdateTopicRequestDto | ✔️ | N/A |
TopicsControllerUpdateTopicResponse
| Error Type | Status Code | Content Type |
|---|---|---|
| models/errors/ErrorDto | 414 | application/json |
| models/errors/ErrorDto | 400, 401, 403, 404, 405, 409, 413, 415 | application/json |
| models/errors/ValidationErrorDto | 422 | application/json |
| models/errors/ErrorDto | 500 | application/json |
| models/errors/APIException | 4XX, 5XX | */* |
Delete a topic by its unique key identifier topicKey. This action is irreversible and will remove all subscriptions to the topic.
package hello.world;
import co.novu.Novu;
import co.novu.models.errors.ErrorDto;
import co.novu.models.errors.ValidationErrorDto;
import co.novu.models.operations.TopicsControllerDeleteTopicResponse;
import java.lang.Exception;
public class Application {
public static void main(String[] args) throws ErrorDto, ValidationErrorDto, Exception {
Novu sdk = Novu.builder()
.secretKey("YOUR_SECRET_KEY_HERE")
.build();
TopicsControllerDeleteTopicResponse res = sdk.topics().remove()
.topicKey("<value>")
.call();
if (res.deleteTopicResponseDto().isPresent()) {
System.out.println(res.deleteTopicResponseDto().get());
}
}
}| Parameter | Type | Required | Description |
|---|---|---|---|
topicKey |
String | ✔️ | The key identifier of the topic |
idempotencyKey |
Optional<String> | ➖ | A header for idempotency purposes |
TopicsControllerDeleteTopicResponse
| Error Type | Status Code | Content Type |
|---|---|---|
| models/errors/ErrorDto | 414 | application/json |
| models/errors/ErrorDto | 400, 401, 403, 404, 405, 409, 413, 415 | application/json |
| models/errors/ValidationErrorDto | 422 | application/json |
| models/errors/ErrorDto | 500 | application/json |
| models/errors/APIException | 4XX, 5XX | */* |
This api will create subscription for subscriberIds for a topic. Its like subscribing to a common interest group. if topic does not exist, it will be created.
package hello.world;
import co.novu.Novu;
import co.novu.models.components.*;
import co.novu.models.errors.ErrorDto;
import co.novu.models.errors.ValidationErrorDto;
import co.novu.models.operations.TopicsControllerCreateTopicSubscriptionsResponse;
import java.lang.Exception;
import java.util.List;
import java.util.Map;
public class Application {
public static void main(String[] args) throws ErrorDto, ValidationErrorDto, Exception {
Novu sdk = Novu.builder()
.secretKey("YOUR_SECRET_KEY_HERE")
.build();
TopicsControllerCreateTopicSubscriptionsResponse res = sdk.topics().createSubscription()
.topicKey("<value>")
.body(CreateTopicSubscriptionsRequestDto.builder()
.subscriptions(List.of(
CreateTopicSubscriptionsRequestDtoSubscription.of(TopicSubscriberIdentifierDto.builder()
.identifier("subscriber-123-subscription-a")
.subscriberId("subscriber-123")
.build()),
CreateTopicSubscriptionsRequestDtoSubscription.of(TopicSubscriberIdentifierDto.builder()
.identifier("subscriber-456-subscription-b")
.subscriberId("subscriber-456")
.build())))
.name("My Topic")
.context(Map.ofEntries(
Map.entry("key", CreateTopicSubscriptionsRequestDtoContextUnion.of("org-acme"))))
.preferences(List.of(
CreateTopicSubscriptionsRequestDtoPreference.of(WorkflowPreferenceRequestDto.builder()
.workflowId("workflow-123")
.condition(Map.ofEntries(
Map.entry("===", List.of(
Map.ofEntries(
Map.entry("var", "tier")),
"premium"))))
.build())))
.build())
.call();
if (res.createSubscriptionsResponseDto().isPresent()) {
System.out.println(res.createSubscriptionsResponseDto().get());
}
}
}| Parameter | Type | Required | Description |
|---|---|---|---|
topicKey |
String | ✔️ | The key identifier of the topic |
idempotencyKey |
Optional<String> | ➖ | A header for idempotency purposes |
body |
CreateTopicSubscriptionsRequestDto | ✔️ | N/A |
TopicsControllerCreateTopicSubscriptionsResponse
| Error Type | Status Code | Content Type |
|---|---|---|
| models/errors/ErrorDto | 414 | application/json |
| models/errors/ErrorDto | 400, 401, 403, 404, 405, 409, 413, 415 | application/json |
| models/errors/ValidationErrorDto | 422 | application/json |
| models/errors/ErrorDto | 500 | application/json |
| models/errors/APIException | 4XX, 5XX | */* |
Retrieve a subscription by its unique identifier for a topic.
package hello.world;
import co.novu.Novu;
import co.novu.models.errors.ErrorDto;
import co.novu.models.errors.ValidationErrorDto;
import co.novu.models.operations.TopicsControllerGetTopicSubscriptionResponse;
import java.lang.Exception;
public class Application {
public static void main(String[] args) throws ErrorDto, ValidationErrorDto, Exception {
Novu sdk = Novu.builder()
.secretKey("YOUR_SECRET_KEY_HERE")
.build();
TopicsControllerGetTopicSubscriptionResponse res = sdk.topics().getSubscriptionById()
.topicKey("<value>")
.identifier("<value>")
.call();
if (res.subscriptionDetailsResponseDto().isPresent()) {
System.out.println(res.subscriptionDetailsResponseDto().get());
}
}
}| Parameter | Type | Required | Description |
|---|---|---|---|
topicKey |
String | ✔️ | The key identifier of the topic |
identifier |
String | ✔️ | The unique identifier of the subscription |
idempotencyKey |
Optional<String> | ➖ | A header for idempotency purposes |
TopicsControllerGetTopicSubscriptionResponse
| Error Type | Status Code | Content Type |
|---|---|---|
| models/errors/ErrorDto | 414 | application/json |
| models/errors/ErrorDto | 400, 401, 403, 404, 405, 409, 413, 415 | application/json |
| models/errors/ValidationErrorDto | 422 | application/json |
| models/errors/ErrorDto | 500 | application/json |
| models/errors/APIException | 4XX, 5XX | */* |