This is a wrapper to access the Sitecore Send API. It builds on the Moosend C# Wrapper.
Make sure the environment variable SITECORE_SEND_API_KEY
is available in the system this code is being executed.
If you want to use dependency injection, then make sure that Foundation.SitecoreSend.config has been deployed to your system.
This method either adds a new subscriber or updates an existing subscriber.
var emailListId = "xyz";
var email = "[email protected]";
var name = "John Doe";
var customFields = new Dictionary<string, string>
{
{ "FirstName", "John" },
{ "LastName", "Doe" }
};
var isMarketingConsent = false;
var isSuccess = _sitecoreSendService.AddSubscriber(emailListId, email, name, customFields, isMarketingConsent);
This method either adds a new subscribers or updates existing subscribers.
var emailListId = "xyz";
var multipleSubscribers = new List<Subscribers>
{
new Subscribers(
"[email protected]",
"John Doe 1",
_sitecoreSendService.ConvertCustomFields(new Dictionary<string, string>
{
{ "FirstName", "John" },
{ "LastName", "Doe 1" }
})),
new Subscribers(
"[email protected]",
"John Doe 2",
_sitecoreSendService.ConvertCustomFields(new Dictionary<string, string>
{
{ "FirstName", "John" },
{ "LastName", "Doe 2" }
}))
};
var isSuccess = _sitecoreSendService.AddMultipleSubscribers(emailListId, subscribers);
var emailListId = "xyz";
var subscribers = _sitecoreSendService.GetSubscribers(emailListId, Sitecore.Foundation.SitecoreSend.Model.SubscriberStatus.Subscribed);