Developer-friendly & type-safe Csharp SDK specifically catered to leverage Novu API.
Important
This SDK is not yet ready for production use. To complete setup please follow the steps outlined in your workspace. Delete this section before > publishing to a package manager.
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;
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
Available methods
- 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
- SetPrimary - Update integration as primary
- ListActive - List active integrations
- Get - List all messages
- Delete - Delete a message
- DeleteByTransactionId - Delete messages by transactionId
- 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 - Update provider credentials
- AppendCredentials - Upsert provider credentials
- DeleteCredentials - Delete provider credentials
- UpdateOnlineStatus - Update subscriber online status
- 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 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;
using System.Collections.Generic;
var sdk = new NovuSDK(secretKey: "YOUR_SECRET_KEY_HERE");
var res = await sdk.TriggerAsync(
retryConfig: new RetryConfig(
strategy: RetryConfig.RetryStrategy.BACKOFF,
backoff: new BackoffStrategy(
initialIntervalMs: 1L,
maxIntervalMs: 50L,
maxElapsedTimeMs: 100L,
exponent: 1.1
),
retryConnectionErrors: false
),
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
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;
using System.Collections.Generic;
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.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
Handling errors in this SDK should largely match your expectations. All operations return a response object or throw an exception.
By default, an API error will raise a Novu.Models.Errors.APIException
exception, which has the following properties:
Property | Type | Description |
---|---|---|
Message |
string | The error message |
Request |
HttpRequestMessage | The HTTP request |
Response |
HttpResponseMessage | The HTTP response |
When custom error responses are specified for an operation, the SDK may also throw their associated exceptions. You can refer to respective Errors tables in SDK docs for more details on possible exception types for each operation. For example, the TriggerAsync
method throws the following exceptions:
Error Type | Status Code | Content Type |
---|---|---|
Novu.Models.Errors.PayloadValidationExceptionDto | 400 | application/json |
Novu.Models.Errors.ErrorDto | 414 | application/json |
Novu.Models.Errors.ErrorDto | 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 | */* |
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 (Exception ex)
{
if (ex is PayloadValidationExceptionDto)
{
// Handle exception data
throw;
}
else if (ex is ErrorDto)
{
// Handle exception data
throw;
}
else if (ex is ErrorDto)
{
// Handle exception data
throw;
}
else if (ex is ValidationErrorDto)
{
// Handle exception data
throw;
}
else if (ex is ErrorDto)
{
// Handle exception data
throw;
}
else if (ex is Novu.Models.Errors.APIException)
{
// Handle default exception
throw;
}
}
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;
using System.Collections.Generic;
var sdk = new NovuSDK(
serverIndex: 1,
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
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;
using System.Collections.Generic;
var sdk = new NovuSDK(
serverUrl: "https://eu.api.novu.co",
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
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.