SitecoreSend.SDK
0.1.10
dotnet add package SitecoreSend.SDK --version 0.1.10
NuGet\Install-Package SitecoreSend.SDK -Version 0.1.10
<PackageReference Include="SitecoreSend.SDK" Version="0.1.10" />
paket add SitecoreSend.SDK --version 0.1.10
#r "nuget: SitecoreSend.SDK, 0.1.10"
// Install SitecoreSend.SDK as a Cake Addin #addin nuget:?package=SitecoreSend.SDK&version=0.1.10 // Install SitecoreSend.SDK as a Cake Tool #tool nuget:?package=SitecoreSend.SDK&version=0.1.10
Sitecore Send SDK (Unofficial)
Provides .NET wrapper around Sitecore Send API
Usage
var apiConfiguration = new ApiConfiguration
{
ApiKey = "[YOUR API KEY]",
Clients = new Dictionary<string, string>()
{
{"[YOUR CLIENT NAME / ALIAS]", "[YOUR CLIENT API KEY]"},
},
};
ISendClient send = new SendClient(apiConfiguration);
var response = await send.Lists.GetAll();
// ensure response is not null and Success is true
if (response is {Success: true})
{
IList<MailingList>? allLists = response.Data?.MailingLists;
// handle allLists
}
// internal API
var internalApi = new InternalApi(InternalApiConfiguration.Create(apiConfiguration));
var allWebsites = await internalApi.Websites.GetAll();
Configuration with DI:
var apiConfiguration = new ApiConfiguration
{
ApiKey = "[YOUR API KEY]",
Clients = ...
};
serviceCollection.AddHttpClient("SitecoreSendClient",
(client) => { client.BaseAddress = new Uri(apiConfiguration.BaseUri); });
serviceCollection.AddSingleton<ISendClient>(provider =>
{
var factory = provider.GetRequiredService<IHttpClientFactory>();
return new SendClient(apiConfiguration,
() => factory.CreateClient("SitecoreSendClient"));
});
Transactional Campaigns
var request = EmailRequestBuilder.StartWithCampaign(campaign)
.AddPersonalization(new Personalization(testEmail, "Igor Zharikov")
{
Substitutions = new Dictionary<string, string>()
{
{"orderNumber", "123456"},
{"paymentMethod", "PayTest"},
{"total", "123.00 USD"},
},
})
.AddAttachment(new EmailAttachment()
{
Content = AttachmentTool.StreamToBase64(File.OpenRead("icon.png")),
Type = "image/png",
FileName = "icon.png",
})
.Build();
var result = await _send.Transactional.Send(request);
Clients switcher
// 'Client1' should be added inside ApiConfiguration.Clients used in constructor
using (new ClientSwitcher("Client1"))
{
var clientLists = await _send.Lists.GetAll();
Assert.True(clientLists?.Success);
}
API Rate limit
Sitecore Send comes with API rate limits for subscribe/unsubscribe endpoints.
Handle within SDK
To check if rate limit occurred the following can be used:
var response = _send.Subscribers.Add(...);
// option 1:
if (response?.Code == KnownErrors.RATE_LIMITING)
{
...
}
// option 2:
if (response?.RateLimitDetails != null)
{
...
}
Current library supports handling of them with 'Wrapping' limited methods with configured policies.
Polly
The following Polly policies configuration can be used: link.
Currently, applies only for SubscribersService
:
new SendClient(
apiConfiguration,
httpClientFactory,
new RateLimiterConfiguration()
{
Subscribers = new SubscribersWrapper()
{
AddSubscriber = SendRateLimits.AddSubscriber.ExecuteAsync,
AddMultipleSubscribers = SendRateLimits.AddMultipleSubscribers.ExecuteAsync,
UnsubscribeFromAllLists = SendRateLimits.UnsubscribeFromAllLists.ExecuteAsync,
UnsubscribeFromList = SendRateLimits.UnsubscribeFromList.ExecuteAsync,
UnsubscribeFromListAndCampaign = SendRateLimits.UnsubscribeFromListAndCampaign.ExecuteAsync,
},
}
);
Avoid rate limit issues
Whenever possible use Get
, Update
methods of ISendClient.Subscribers
.
E.g. if you need to ensure user exists in the list, use extension methods:
// check if subscriber exists => then update, if not => create
_send.Subscribers.CreateOrUpdate(listId, ...);
// check if user is subscribed to the list, if subscribeIfNotExists == true => subscribe to list
_send.Subscribers.EnsureSubscribed(listId, email, subscribeIfNotExists);
Integration tests
Overview
Integration tests are located in SitecoreSend.SDK.Tests
project.
Running locally
Create file appsettings.local.jsonc
based on appsettings.jsonc
in SitecoreSend.SDK.Tests
project and populate it with your own values.
Contribute / Bug / Help
You can contact me via email or in Sitecore Slack: zharikovigor97@gmail.com
. Or please open an issue.
Roadmap
Documented API
- Mailing list service
- Subscribers service
- Campaigns service
- Segments service
- Transactional Campaigns Methods
Internal API
- Websites management (WIP)
- Automations
- Senders API
- Landing Pages
Tracking API
- Tracking API
SMTP API
- SMTP: use
SmtpClient
together withSitecoreSend.SDK.Extensions.SmtpExtensions
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 is compatible. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.6.1
- System.Net.Http.Json (>= 5.0.0)
- System.Text.Json (>= 5.0.0)
-
.NETStandard 2.0
- System.Net.Http.Json (>= 5.0.0)
- System.Text.Json (>= 5.0.0)
-
net6.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.1.10 | 73 | 11/19/2024 |
0.1.9 | 65 | 10/22/2024 |
0.1.8 | 394 | 9/18/2024 |
0.1.7.2 | 333 | 6/17/2024 |
0.1.7.1 | 141 | 6/7/2024 |
0.1.7 | 97 | 6/7/2024 |
0.1.6.5 | 94 | 6/6/2024 |
0.1.6.4 | 92 | 6/6/2024 |
0.1.6.3 | 94 | 6/6/2024 |
0.1.6.2 | 92 | 6/6/2024 |
0.1.6.1 | 105 | 6/5/2024 |
0.1.6 | 99 | 6/5/2024 |
0.1.5-alpha | 83 | 4/26/2024 |
0.1.4-alpha | 72 | 4/26/2024 |
0.1.3-alpha | 72 | 4/26/2024 |
0.1.2-preview-2 | 86 | 4/25/2024 |
0.1.2-preview-1 | 91 | 4/25/2024 |
0.1.0 | 113 | 4/25/2024 |