.NET Library

This is a client for the Sailthru REST API.
View on Github | Download

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

Send

//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

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

Send Cancel

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

Get Send

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

Template

Get Template

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

Save Template

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

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

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

Stats

Get Stat

response = client.GetStat("list");

User

Set Horizon Cookie on User at Login

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

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

Import from List

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.

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

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

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); 
    }
}
Top