Skip to content

Latest commit

 

History

31 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SendyClient.Net

A Sendy client to interact in .Net Core applications with the Sendy API!

NuGet

Sendy

It can be used to perform the following Sendy API actions:

  • Subscribe (including custom fields)
  • Unsubscribe
  • Delete subscriber
  • Subscription status
  • Active subscriber count
  • Create campaign (and send)
  • Create list (new!)

Available on Nuget

SendyClient.Net is available to download via NuGet!

How to use

var sendyClient = new SendyClient(new Uri("https://mysendy"), "mySendySecret");

var result = await sendyClient.SubscribeAsync("sjaan@banaan.nl", "Sjaan", "myListId");

Subscribe with custom fields 'birthday' and 'logintoken'

var sendyClient = new SendyClient(new Uri("https://mysendy"), "mySendySecret");
var customFields = new Dictionary<string, string> {{"birthday", "12/9/1976"}, {"logintoken", "x4bla9!bg"}};

var result = await sendyClient.SubscribeAsync("sjaan@banaan.nl", "Sjaan", "myListId", customFields);

If you would like to use the campaign API, download it first.

var sendyClient = new SendyClient(new Uri("https://mysendy"), "mySendySecret");

var campaign = new Campaign
{
  BrandId = 1,
  FromEmail = "noreply@fromme.com",
  FromName = "Jeroen",
  HtmlText = "<html><body><b>Hi</b></body></html>",
  PlainText = "Hi",
  Querystring = "querystring=sjaak",
  ReplyTo = "sjaan@banaan.nl",
  Subject = "Sent with SendyClient.Net!",
  Title = "Campaign demo"
};

result = await sendyClient.CreateCampaignAsync(campaign, false, null);

Optionally, a campaign can also control open/click tracking and be scheduled for a later date instead of sent immediately:

var campaign = new Campaign
{
  BrandId = 1,
  FromEmail = "noreply@fromme.com",
  FromName = "Jeroen",
  HtmlText = "<html><body><b>Hi</b></body></html>",
  PlainText = "Hi",
  ReplyTo = "sjaan@banaan.nl",
  Subject = "Sent with SendyClient.Net!",
  Title = "Campaign demo",
  TrackOpens = TrackingOption.Enabled,
  TrackClicks = TrackingOption.Anonymous,
  ScheduleDateTime = new DateTime(2021, 6, 15, 18, 5, 0), // minutes must be a multiple of 5
  ScheduleTimezone = "America/New_York"
};

// send_campaign must be true (send: true below) for scheduling to take effect, and requires one or more lists/segments.
result = await sendyClient.CreateCampaignAsync(campaign, true, new Groups(new[] { "myListId" }));

Create list API

The create list is a new API. Copy the Sendy directory to your Sendy installation. This will add a new API call to create a list, including custom fields when necessary.

endpoint: /api/lists/create.php

POST data:

  • api_key
  • brand_id
  • list_name - the name of the new list (mandatory).
  • custom_fields - a comma separated list of new custom field names. Not allowed are email and name (similar to the UI validations)
  • field_types - possible values: Text or Date

Return value The id of the list that is created or an error message if something went wrong.

After this you can simply call:

var sendyClient = new SendyClient(new Uri("https://mysendy"), "mySendySecret");
var list = new MailingList
{
  BrandId = 1,
  Name = "Foo list"
};

list.CustomFields.Add(new CustomField("custom field 1"));
list.CustomFields.Add(new CustomField("custom field 2", CustomField.DataTypes.Date));

var result = await sendyClient.CreateListAsync(list);

API updates

The SendyClient class constructor now includes a new parameter named apiVer where you can pass in the version of Sendy you're working against. If not supplied it won't support version 3 enhancements.

var sendyClient = new SendyClient(new Uri("https://mysendy"), "mySendySecret", new Version(3, 0, 6));

Version 3 changes

  • Subscribe API now includes country, ipaddress, referrer & gdpr parameters.
  • CreateCampaign API now includes segment_ids, exclude_list_ids & exclude_segments_ids parameters.
  • CreateCampaign API now also includes track_opens, track_clicks, schedule_date_time & schedule_timezone parameters, and recognizes the "Campaign scheduled" response.

Questions

Feel free to create an issue, or even better: submit a pull request.

About

A Sendy client, now support for .Net Core!

Resources

Stars

4 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages