.NET Library

This is a client for the REST API.

Installation

The client is available on GitHub and can also be installed as a dependency using Nuget.

Authentication

You can find your API key and secret on the API Postbacks Settings page when logged in to the platform.

Copy
string apiKey = "***************";
string secret = "***************";
SailthruClient client = new SailthruClient(apiKey, secret);
SailthruResponse response;

Examples

Send

Copy
//Send
SailthruResponse response;
response = client.Send("default2", "abc@sailthru.com");

//recommended to check response from server
if (response.IsOK())
{
    //do something
}
else
{
    String errorrResponse = response.RawResponse;
}

Multi Send

Copy
//multi send
String[] emails = {"abc@sailthru.com", "xyz@gmail.com"};
response = client.Multisend("default", emails)

Send Cancel

Copy
//send cancel
//response = client.CancelSend("TTimJmdj2apLAAPM");

Get Send

Copy
//get send
String sendId = "TTizbmdj2YheAAUu";
response = client.GetSend(sendId);

Template

Get Template

Copy
String templateId = "default2";
response = client.GetTemplate(templatedId);

Save Template

Copy
TemplateRequest templateRequest = new TemplateRequest();
templateRequest.FromEmail = "praj@sailthru.com";
templateRequest.FromName = "Sailthru";
templateRequest.GoogleAnalytics = TemplateRequest.GoogleAnalyticsType.Disabled;
templateRequest.Template = "default2555";

response = client.SaveTemplate(templateRequest);

Blast

Set Blast

Copy
BlastRequest blastRequest = new BlastRequest();
blastRequest.Name = "Blast Name1";
blastRequest.ContentHtml = "<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. </p>";
blastRequest.List = "Sample List";
blastRequest.ContentText = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, ";
blastRequest.Subject = "Sample Subject";
blastRequest.ScheduleTime = "+3 hours";
blastRequest.FromName = "C# Client";
blastRequest.FromEmail = "no-reply@sailthru.com";

response = client.ScheduleBlast(blastRequest);

Get Blast

Copy
String blastId = "252525";
response = client.GetBlast(blastId);

Stats

Get Stat

Copy
response = client.GetStat("list");

User

Set Horizon Cookie on User at Login

Copy
UserRequest request = new UserRequest();
request.Id = "joe@example.com";
Hashtable fieldsHashtable = new Hashtable();
fieldsHashtable.Add("keys", 1);
request.Fields = fieldsHashtable;
request.Login = "site";
SailthruResponse response = client.SetUser(request);
if (response.HashtableResponse.ContainsKey ("keys"))
{
  Hashtable keys = (Hashtable)response.HashtableResponse["keys"];
  var cookie = keys["cookie"];
  // Handle cookie
}

Job

Import from CSV file

Copy
client.ProcessImportJob("my_list", "/tmp/my_users.csv");

Import from List

Copy
List<String> emails = new List<String>() {"example@example.com", "hello@world.com"};
client.ProcessImportJob("my_list", emails);

Export List Data to File

Select a subset of fields by specifying "fields" in a parameter hashtable. This example selects only the clicks field.

Copy
Hashtable exportParams = new Hashtable(); 
Hashtable fields = new Hashtable();
exportParams.Add("job", "export_list_data"); 
exportParams.Add("list", listName);
fields.Add("clicks", 1);
exportParams.Add("fields", fields);

Purchase

Pass shopping cart purchase data

Copy
string apiKey = "***";
string secret = "***";
SailthruClient client = new SailthruClient(apiKey, secret);
SailthruResponse response;
PurchaseRequest request = new PurchaseRequest();

request.Email = "support@sailthru.com";
ArrayList items = new ArrayList();
Hashtable firstitem = new Hashtable();
request.MessageID = "23423.231";
request.Incomplete = 1;
request.ReminderTemplate = "abandonedcarttemplate";
request.ReminderTime = "+3 hours";
int firstitemqty = 1;
String firstitemid = "abc";
String firstitemtitle = "This new product";
int firstitemprice = 1099;
String firstitemurl = "http://www.example.com/thisnewproduct.html";
firstitem.Add("qty", firstitemqty);
firstitem.Add("id", firstitemid);
firstitem.Add("title", firstitemtitle);
firstitem.Add("price", firstitemprice);
firstitem.Add("url", firstitemurl);
items.Add(firstitem);
request.Items = items;

response = client.Purchase(request);
Console.Write(response.RawResponse);

Rate Limits

Copy
Hashtable lastRateLimitInfo = sailthruClient.getLastRateLimitInfo("user", "post");
// getLastRateLimitInfo returns null if given endpoint/method wasn't triggered previously
if (lastRateLimitInfo != null) {
    int limit = lastRateLimitInfo['limit'];
    int remaining = lastRateLimitInfo['remaining'];
    DateTime reset = (DateTime)lastRateLimitInfo['reset'];
    // throttle api calls based on last rate limit info
    if (remaining <= 0) {
        TimeSpan time_span_till_reset = reset.Subtract(DateTime.now());
        // sleep or perform other business logic before next user api call
        Thread.Sleep(time_span_till_reset); 
    }
}

Custom Event

Copy
EventRequest request = new EventRequest();
request.Id = "abc@sailthru.com";
request.Event = "dotnet";
response = client.PostEvent(request);