Skip to content

Latest commit

 

History

History
311 lines (242 loc) · 20.4 KB

File metadata and controls

311 lines (242 loc) · 20.4 KB

Topics.Subscriptions

Overview

Available Operations

  • List - List topic subscriptions
  • Create - Create topic subscriptions
  • Delete - Delete topic subscriptions
  • GetSubscription - Retrieve a topic subscription
  • Update - Update a topic subscription

List

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

Example Usage

using Novu;
using Novu.Models.Components;
using Novu.Models.Requests;
using System.Collections.Generic;

var sdk = new NovuSDK(secretKey: "YOUR_SECRET_KEY_HERE");

TopicsControllerListTopicSubscriptionsRequest req = new TopicsControllerListTopicSubscriptionsRequest() {
    TopicKey = "<value>",
    Limit = 10D,
    ContextKeys = new List<string>() {
        "tenant:org-123",
        "region:us-east-1",
    },
};

var res = await sdk.Topics.Subscriptions.ListAsync(req);

// 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
Novu.Models.Errors.ErrorDto 414 application/json
Novu.Models.Errors.ErrorDto 400, 401, 403, 404, 405, 409, 413, 415 application/json
Novu.Models.Errors.ValidationErrorDto 422 application/json
Novu.Models.Errors.ErrorDto 500 application/json
Novu.Models.Errors.APIException 4XX, 5XX */*

Create

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.

Example Usage

using Novu;
using Novu.Models.Components;
using System.Collections.Generic;

var sdk = new NovuSDK(secretKey: "YOUR_SECRET_KEY_HERE");

var res = await sdk.Topics.Subscriptions.CreateAsync(
    topicKey: "<value>",
    createTopicSubscriptionsRequestDto: new CreateTopicSubscriptionsRequestDto() {
        Subscriptions = new List<Novu.Models.Components.Subscriptions>() {
            Novu.Models.Components.Subscriptions.CreateTopicSubscriberIdentifierDto(
                new TopicSubscriberIdentifierDto() {
                    Identifier = "subscriber-123-subscription-a",
                    SubscriberId = "subscriber-123",
                }
            ),
            Novu.Models.Components.Subscriptions.CreateTopicSubscriberIdentifierDto(
                new TopicSubscriberIdentifierDto() {
                    Identifier = "subscriber-456-subscription-b",
                    SubscriberId = "subscriber-456",
                }
            ),
        },
        Name = "My Topic",
        Context = new Dictionary<string, CreateTopicSubscriptionsRequestDtoContext>() {
            { "key", CreateTopicSubscriptionsRequestDtoContext.CreateStr(
                "org-acme"
            ) },
        },
        Preferences = new List<Novu.Models.Components.Preferences>() {
            Novu.Models.Components.Preferences.CreateWorkflowPreferenceRequestDto(
                new WorkflowPreferenceRequestDto() {
                    Condition = new Dictionary<string, object>() {
                        { "===", new List<object>() {
                            new Dictionary<string, object>() {
                                { "var", "tier" },
                            },
                            "premium",
                        } },
                    },
                    WorkflowId = "workflow-123",
                }
            ),
        },
    }
);

// handle response

Parameters

Parameter Type Required Description
TopicKey string ✔️ The key identifier of the topic
CreateTopicSubscriptionsRequestDto CreateTopicSubscriptionsRequestDto ✔️ N/A
IdempotencyKey string A header for idempotency purposes

Response

TopicsControllerCreateTopicSubscriptionsResponse

Errors

Error Type Status Code Content Type
Novu.Models.Errors.ErrorDto 414 application/json
Novu.Models.Errors.ErrorDto 400, 401, 403, 404, 405, 409, 413, 415 application/json
Novu.Models.Errors.ValidationErrorDto 422 application/json
Novu.Models.Errors.ErrorDto 500 application/json
Novu.Models.Errors.APIException 4XX, 5XX */*

Delete

Delete subscriptions for subscriberIds for a topic.

Example Usage

using Novu;
using Novu.Models.Components;
using System.Collections.Generic;

var sdk = new NovuSDK(secretKey: "YOUR_SECRET_KEY_HERE");

var res = await sdk.Topics.Subscriptions.DeleteAsync(
    topicKey: "<value>",
    deleteTopicSubscriptionsRequestDto: new DeleteTopicSubscriptionsRequestDto() {
        Subscriptions = new List<DeleteTopicSubscriptionsRequestDtoSubscriptions>() {
            DeleteTopicSubscriptionsRequestDtoSubscriptions.CreateDeleteTopicSubscriberIdentifierDto(
                new DeleteTopicSubscriberIdentifierDto() {
                    Identifier = "subscriber-123-subscription-a",
                    SubscriberId = "subscriber-123",
                }
            ),
            DeleteTopicSubscriptionsRequestDtoSubscriptions.CreateDeleteTopicSubscriberIdentifierDto(
                new DeleteTopicSubscriberIdentifierDto() {
                    SubscriberId = "subscriber-456",
                }
            ),
            DeleteTopicSubscriptionsRequestDtoSubscriptions.CreateDeleteTopicSubscriberIdentifierDto(
                new DeleteTopicSubscriberIdentifierDto() {
                    Identifier = "subscriber-789-subscription-b",
                }
            ),
        },
    }
);

// handle response

Parameters

Parameter Type Required Description
TopicKey string ✔️ The key identifier of the topic
DeleteTopicSubscriptionsRequestDto DeleteTopicSubscriptionsRequestDto ✔️ N/A
IdempotencyKey string A header for idempotency purposes

Response

TopicsControllerDeleteTopicSubscriptionsResponse

Errors

Error Type Status Code Content Type
Novu.Models.Errors.ErrorDto 414 application/json
Novu.Models.Errors.ErrorDto 400, 401, 403, 404, 405, 409, 413, 415 application/json
Novu.Models.Errors.ValidationErrorDto 422 application/json
Novu.Models.Errors.ErrorDto 500 application/json
Novu.Models.Errors.APIException 4XX, 5XX */*

GetSubscription

Retrieve a subscription by its unique identifier for a topic.

Example Usage

using Novu;
using Novu.Models.Components;

var sdk = new NovuSDK(secretKey: "YOUR_SECRET_KEY_HERE");

var res = await sdk.Topics.Subscriptions.GetSubscriptionAsync(
    topicKey: "<value>",
    identifier: "<value>"
);

// handle response

Parameters

Parameter Type Required Description
TopicKey string ✔️ The key identifier of the topic
Identifier string ✔️ The unique identifier of the subscription
IdempotencyKey string A header for idempotency purposes

Response

TopicsControllerGetTopicSubscriptionResponse

Errors

Error Type Status Code Content Type
Novu.Models.Errors.ErrorDto 414 application/json
Novu.Models.Errors.ErrorDto 400, 401, 403, 404, 405, 409, 413, 415 application/json
Novu.Models.Errors.ValidationErrorDto 422 application/json
Novu.Models.Errors.ErrorDto 500 application/json
Novu.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

using Novu;
using Novu.Models.Components;
using System.Collections.Generic;

var sdk = new NovuSDK(secretKey: "YOUR_SECRET_KEY_HERE");

var res = await sdk.Topics.Subscriptions.UpdateAsync(
    topicKey: "<value>",
    identifier: "<value>",
    updateTopicSubscriptionRequestDto: new UpdateTopicSubscriptionRequestDto() {
        Name = "My Subscription",
        Preferences = new List<UpdateTopicSubscriptionRequestDtoPreferences>() {
            UpdateTopicSubscriptionRequestDtoPreferences.CreateWorkflowPreferenceRequestDto(
                new WorkflowPreferenceRequestDto() {
                    Condition = new Dictionary<string, object>() {
                        { "===", new List<object>() {
                            new Dictionary<string, object>() {
                                { "var", "tier" },
                            },
                            "premium",
                        } },
                    },
                    WorkflowId = "workflow-123",
                }
            ),
        },
    }
);

// handle response

Parameters

Parameter Type Required Description
TopicKey string ✔️ The key identifier of the topic
Identifier string ✔️ The unique identifier of the subscription
UpdateTopicSubscriptionRequestDto UpdateTopicSubscriptionRequestDto ✔️ N/A
IdempotencyKey string A header for idempotency purposes

Response

TopicsControllerUpdateTopicSubscriptionResponse

Errors

Error Type Status Code Content Type
Novu.Models.Errors.ErrorDto 414 application/json
Novu.Models.Errors.ErrorDto 400, 401, 403, 404, 405, 409, 413, 415 application/json
Novu.Models.Errors.ValidationErrorDto 422 application/json
Novu.Models.Errors.ErrorDto 500 application/json
Novu.Models.Errors.APIException 4XX, 5XX */*