Skip to content

Latest commit

 

History

History
221 lines (169 loc) · 14.2 KB

File metadata and controls

221 lines (169 loc) · 14.2 KB

Topics.Subscriptions

Overview

Available Operations

  • list - List topic subscriptions
  • delete - Delete topic subscriptions
  • update - Update a topic subscription

list

List all subscriptions of subscribers for a topic. Checkout all available filters in the query section.

Example Usage

package hello.world;

import co.novu.Novu;
import co.novu.models.errors.ErrorDto;
import co.novu.models.errors.ValidationErrorDto;
import co.novu.models.operations.TopicsControllerListTopicSubscriptionsRequest;
import co.novu.models.operations.TopicsControllerListTopicSubscriptionsResponse;
import java.lang.Exception;
import java.util.List;

public class Application {

    public static void main(String[] args) throws ErrorDto, ValidationErrorDto, Exception {

        Novu sdk = Novu.builder()
                .secretKey("YOUR_SECRET_KEY_HERE")
            .build();

        TopicsControllerListTopicSubscriptionsRequest req = TopicsControllerListTopicSubscriptionsRequest.builder()
                .topicKey("<value>")
                .limit(10d)
                .contextKeys(List.of(
                    "tenant:org-123",
                    "region:us-east-1"))
                .build();

        TopicsControllerListTopicSubscriptionsResponse res = sdk.topics().subscriptions().list()
                .request(req)
                .call();

        if (res.listTopicSubscriptionsResponseDto().isPresent()) {
            // handle response
        }
    }
}

Parameters

Parameter Type Required Description
request TopicsControllerListTopicSubscriptionsRequest ✔️ The request object to use for the request.

Response

TopicsControllerListTopicSubscriptionsResponse

Errors

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

Delete subscriptions for subscriberIds for a topic.

Example Usage

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.TopicsControllerDeleteTopicSubscriptionsResponse;
import java.lang.Exception;
import java.util.List;

public class Application {

    public static void main(String[] args) throws ErrorDto, ValidationErrorDto, Exception {

        Novu sdk = Novu.builder()
                .secretKey("YOUR_SECRET_KEY_HERE")
            .build();

        TopicsControllerDeleteTopicSubscriptionsResponse res = sdk.topics().subscriptions().delete()
                .topicKey("<value>")
                .body(DeleteTopicSubscriptionsRequestDto.builder()
                    .subscriptions(List.of(
                        DeleteTopicSubscriptionsRequestDtoSubscription.of(DeleteTopicSubscriberIdentifierDto.builder()
                            .identifier("subscriber-123-subscription-a")
                            .subscriberId("subscriber-123")
                            .build()),
                        DeleteTopicSubscriptionsRequestDtoSubscription.of(DeleteTopicSubscriberIdentifierDto.builder()
                            .subscriberId("subscriber-456")
                            .build()),
                        DeleteTopicSubscriptionsRequestDtoSubscription.of(DeleteTopicSubscriberIdentifierDto.builder()
                            .identifier("subscriber-789-subscription-b")
                            .build())))
                    .build())
                .call();

        if (res.deleteTopicSubscriptionsResponseDto().isPresent()) {
            // handle response
        }
    }
}

Parameters

Parameter Type Required Description
topicKey String ✔️ The key identifier of the topic
idempotencyKey Optional<String> A header for idempotency purposes
body DeleteTopicSubscriptionsRequestDto ✔️ N/A

Response

TopicsControllerDeleteTopicSubscriptionsResponse

Errors

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

Update a subscription by its unique identifier for a topic. You can update the preferences and name associated with the subscription.

Example Usage

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.TopicsControllerUpdateTopicSubscriptionResponse;
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();

        TopicsControllerUpdateTopicSubscriptionResponse res = sdk.topics().subscriptions().update()
                .topicKey("<value>")
                .identifier("<value>")
                .body(UpdateTopicSubscriptionRequestDto.builder()
                    .name("My Subscription")
                    .preferences(List.of(
                        UpdateTopicSubscriptionRequestDtoPreference.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.subscriptionResponseDto().isPresent()) {
            // handle response
        }
    }
}

Parameters

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
body UpdateTopicSubscriptionRequestDto ✔️ N/A

Response

TopicsControllerUpdateTopicSubscriptionResponse

Errors

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 */*