Developer-friendly & type-safe Csharp SDK specifically catered to leverage Novu API.
Novu API: Novu REST API. Please see https://docs.novu.co/api-reference for more details.
For more information about the API: Novu Documentation
To add the NuGet package to a .NET project:
dotnet add package Novu
To add a reference to a local instance of the SDK in a .NET project:
dotnet add reference src/Novu/Novu.csproj
using Novu;
using Novu.Models.Components;
using System.Collections.Generic;
var sdk = new NovuSDK(secretKey: "YOUR_SECRET_KEY_HERE");
var res = await sdk.TriggerAsync(triggerEventRequestDto: new TriggerEventRequestDto() {
WorkflowId = "workflow_identifier",
Payload = new Dictionary<string, object>() {
{ "comment_id", "string" },
{ "post", new Dictionary<string, object>() {
{ "text", "string" },
} },
},
Overrides = new Overrides() {},
To = To.CreateStr(
"SUBSCRIBER_ID"
),
});
// handle response
using Novu;
using Novu.Models.Components;
var sdk = new NovuSDK(secretKey: "YOUR_SECRET_KEY_HERE");
var res = await sdk.CancelAsync(transactionId: "<id>");
// handle response
using Novu;
using Novu.Models.Components;
using System.Collections.Generic;
var sdk = new NovuSDK(secretKey: "YOUR_SECRET_KEY_HERE");
var res = await sdk.BroadcastAsync(triggerEventToAllRequestDto: new TriggerEventToAllRequestDto() {
Name = "<value>",
Payload = new Dictionary<string, object>() {
{ "comment_id", "string" },
{ "post", new Dictionary<string, object>() {
{ "text", "string" },
} },
},
Overrides = new TriggerEventToAllRequestDtoOverrides() {
AdditionalProperties = new Dictionary<string, Dictionary<string, object>>() {
{ "fcm", new Dictionary<string, object>() {
{ "data", new Dictionary<string, object>() {
{ "key", "value" },
} },
} },
},
},
});
// handle response
using Novu;
using Novu.Models.Components;
using System.Collections.Generic;
var sdk = new NovuSDK(secretKey: "YOUR_SECRET_KEY_HERE");
var res = await sdk.TriggerBulkAsync(bulkTriggerEventDto: new BulkTriggerEventDto() {
Events = new List<TriggerEventRequestDto>() {
new TriggerEventRequestDto() {
WorkflowId = "workflow_identifier",
Payload = new Dictionary<string, object>() {
{ "comment_id", "string" },
{ "post", new Dictionary<string, object>() {
{ "text", "string" },
} },
},
Overrides = new Overrides() {},
To = To.CreateStr(
"SUBSCRIBER_ID"
),
},
new TriggerEventRequestDto() {
WorkflowId = "workflow_identifier",
Payload = new Dictionary<string, object>() {
{ "comment_id", "string" },
{ "post", new Dictionary<string, object>() {
{ "text", "string" },
} },
},
Overrides = new Overrides() {},
To = To.CreateStr(
"SUBSCRIBER_ID"
),
},
new TriggerEventRequestDto() {
WorkflowId = "workflow_identifier",
Payload = new Dictionary<string, object>() {
{ "comment_id", "string" },
{ "post", new Dictionary<string, object>() {
{ "text", "string" },
} },
},
Overrides = new Overrides() {},
To = To.CreateStr(
"SUBSCRIBER_ID"
),
},
},
});
// handle response
This SDK supports the following security scheme globally:
Name | Type | Scheme |
---|---|---|
SecretKey |
apiKey | API key |
To authenticate with the API the SecretKey
parameter must be set when initializing the SDK client instance. For example:
using Novu;
using Novu.Models.Components;
var sdk = new NovuSDK(secretKey: "YOUR_SECRET_KEY_HERE");
var res = await sdk.InboundWebhooksControllerHandleWebhookAsync(
environmentId: "<id>",
integrationId: "<id>"
);
// handle response
Available methods
- GetTags - Get environment tags
- Create - Create an environment
- List - List all environments
- Update - Update an environment
- Delete - Delete an environment
- GetAll - List all integrations
- Create - Create an integration
- Update - Update an integration
- Delete - Delete an integration
- IntegrationsControllerAutoConfigureIntegration - Auto-configure an integration for inbound webhooks
- SetPrimary - Update integration as primary
- ListActive - List active integrations
- Create - Create a layout
- List - List all layouts
- Update - Update a layout
- Retrieve - Retrieve a layout
- Delete - Delete a layout
- Duplicate - Duplicate a layout
- GeneratePreview - Generate layout preview
- Usage - Get layout usage
- Get - List all messages
- Delete - Delete a message
- DeleteByTransactionId - Delete messages by transactionId
- InboundWebhooksControllerHandleWebhook
- Trigger - Trigger event
- Cancel - Cancel triggered event
- Broadcast - Broadcast event to all
- TriggerBulk - Bulk trigger event
- Search - Search subscribers
- Create - Create a subscriber
- Retrieve - Retrieve a subscriber
- Patch - Update a subscriber
- Delete - Delete a subscriber
- CreateBulk - Bulk create subscribers
- UpdateCredentials - Upsert provider credentials
- AppendCredentials - Update provider credentials
- DeleteCredentials - Delete provider credentials
- UpdateOnlineStatus - Update subscriber online status
- BulkUpdate - Bulk update subscriber preferences
- List - Retrieve subscriber subscriptions
- UpdateAction - Update notification action status
- MarkAll - Update all notifications state
- MarkAllAs - Update notifications state
- Feed - Retrieve subscriber notifications
- UnseenCount - Retrieve unseen notifications count
- List - List all topics
- Create - Create a topic
- Get - Retrieve a topic
- Update - Update a topic
- Delete - Delete a topic
- List - List topic subscriptions
- Create - Create topic subscriptions
- Delete - Delete topic subscriptions
- Get - Check topic subscriber
- Create - Create a translation
- Retrieve - Retrieve a translation
- Delete - Delete a translation
- Upload - Upload translation files
- Retrieve - Retrieve master translations JSON
- Import - Import master translations JSON
- Upload - Upload master translations JSON file
- Create - Create a workflow
- List - List all workflows
- Update - Update a workflow
- Get - Retrieve a workflow
- Delete - Delete a workflow
- Patch - Update a workflow
- Sync - Sync a workflow
- Retrieve - Retrieve workflow step
Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.
To change the default retry strategy for a single API call, simply pass a RetryConfig
to the call:
using Novu;
using Novu.Models.Components;
var sdk = new NovuSDK(secretKey: "YOUR_SECRET_KEY_HERE");
var res = await sdk.InboundWebhooksControllerHandleWebhookAsync(
retryConfig: new RetryConfig(
strategy: RetryConfig.RetryStrategy.BACKOFF,
backoff: new BackoffStrategy(
initialIntervalMs: 1L,
maxIntervalMs: 50L,
maxElapsedTimeMs: 100L,
exponent: 1.1
),
retryConnectionErrors: false
),
environmentId: "<id>",
integrationId: "<id>"
);
// handle response
If you'd like to override the default retry strategy for all operations that support retries, you can use the RetryConfig
optional parameter when intitializing the SDK:
using Novu;
using Novu.Models.Components;
var sdk = new NovuSDK(
retryConfig: new RetryConfig(
strategy: RetryConfig.RetryStrategy.BACKOFF,
backoff: new BackoffStrategy(
initialIntervalMs: 1L,
maxIntervalMs: 50L,
maxElapsedTimeMs: 100L,
exponent: 1.1
),
retryConnectionErrors: false
),
secretKey: "YOUR_SECRET_KEY_HERE"
);
var res = await sdk.InboundWebhooksControllerHandleWebhookAsync(
environmentId: "<id>",
integrationId: "<id>"
);
// handle response
NovuError
is the base exception class for all HTTP error responses. It has the following properties:
Property | Type | Description |
---|---|---|
Message |
string | Error message |
Request |
HttpRequestMessage | HTTP request object |
Response |
HttpResponseMessage | HTTP response object |
Some exceptions in this SDK include an additional Payload
field, which will contain deserialized custom error data when present. Possible exceptions are listed in the Error Classes section.
using Novu;
using Novu.Models.Components;
using Novu.Models.Errors;
using System.Collections.Generic;
var sdk = new NovuSDK(secretKey: "YOUR_SECRET_KEY_HERE");
try
{
var res = await sdk.TriggerAsync(triggerEventRequestDto: new TriggerEventRequestDto() {
WorkflowId = "workflow_identifier",
Payload = new Dictionary<string, object>() {
{ "comment_id", "string" },
{ "post", new Dictionary<string, object>() {
{ "text", "string" },
} },
},
Overrides = new Overrides() {},
To = To.CreateStr(
"SUBSCRIBER_ID"
),
});
// handle response
}
catch (NovuError ex) // all SDK exceptions inherit from NovuError
{
// ex.ToString() provides a detailed error message
System.Console.WriteLine(ex);
// Base exception fields
HttpRequestMessage request = ex.Request;
HttpResponseMessage response = ex.Response;
var statusCode = (int)response.StatusCode;
var responseBody = ex.Body;
if (ex is PayloadValidationExceptionDto) // different exceptions may be thrown depending on the method
{
// Check error data fields
PayloadValidationExceptionDtoPayload payload = ex.Payload;
double StatusCode = payload.StatusCode;
string Timestamp = payload.Timestamp;
// ...
}
// An underlying cause may be provided
if (ex.InnerException != null)
{
Exception cause = ex.InnerException;
}
}
catch (System.Net.Http.HttpRequestException ex)
{
// Check ex.InnerException for Network connectivity errors
}
Primary exceptions:
NovuError
: The base class for HTTP error responses.ErrorDto
: *ValidationErrorDto
: Unprocessable Entity. Status code422
. *
Less common exceptions (5)
-
System.Net.Http.HttpRequestException
: Network connectivity error. For more details about the underlying cause, inspect theex.InnerException
. -
Inheriting from
NovuError
:PayloadValidationExceptionDto
: Status code400
. Applicable to 3 of 75 methods.*SubscriberResponseDto
: Created. Status code409
. Applicable to 1 of 75 methods.*TopicResponseDto
: OK. Status code409
. Applicable to 1 of 75 methods.*ResponseValidationError
: Thrown when the response data could not be deserialized into the expected type.
* Refer to the relevant documentation to determine whether an exception applies to a specific operation.
You can override the default server globally by passing a server index to the serverIndex: int
optional parameter when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers:
# | Server | Description |
---|---|---|
0 | https://api.novu.co |
|
1 | https://eu.api.novu.co |
using Novu;
using Novu.Models.Components;
var sdk = new NovuSDK(
serverIndex: 1,
secretKey: "YOUR_SECRET_KEY_HERE"
);
var res = await sdk.InboundWebhooksControllerHandleWebhookAsync(
environmentId: "<id>",
integrationId: "<id>"
);
// handle response
The default server can also be overridden globally by passing a URL to the serverUrl: string
optional parameter when initializing the SDK client instance. For example:
using Novu;
using Novu.Models.Components;
var sdk = new NovuSDK(
serverUrl: "https://eu.api.novu.co",
secretKey: "YOUR_SECRET_KEY_HERE"
);
var res = await sdk.InboundWebhooksControllerHandleWebhookAsync(
environmentId: "<id>",
integrationId: "<id>"
);
// handle response
This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.
While we value open-source contributions to this SDK, this library is generated programmatically. Any manual changes added to internal files will be overwritten on the next generation. We look forward to hearing your feedback. Feel free to open a PR or an issue with a proof of concept and we'll do our best to include it in a future release.