A simple client library to remotely access the Sailthru REST API
as per http://docs.sailthru.com/api
By default, it will make request in JSON
format.
It can make requests to following API calls:
$api_key = "api_key";
$api_secret = 'secret';
$sailthruClient = new Sailthru_Client($api_key, $api_secret);
### Generic Example
try {
$response = $sailthruClient->getSend("TUMVqWdj2exnAAV-");
if ( !isset($response['error']) ) {
// everything OK
// do something here
} else {
// handle API error
}
} catch (Sailthru_Client_Exception $e) {
// deal with exceptions
}
//send
$response = $sailthruClient->send('temlate-name', '[email protected]', array('name' => 'unix'), array('test' => 1));
//multi send
$response = $sailthruClient->multisend('default', '[email protected],[email protected]', array('name' => 'unix'), array(), array('test' => 1));
//get send
$response = $sailthruClient->getSend("TUMVqWdj2exnAAV-");
//cancel send
$response = $sailthruClient->cancelSend("TUMYT2dj2fl1AABD");
//get email information of a user
$response = $sailthruClient->getEmail("[email protected]");
//update user info
$email = '[email protected]';
$vars = array('name' => 'Prajwal Tuladhar');
$lists = array('list-a' => 1, 'list-b' => 1);
$templates = array('template-1' => 1, 'template-2' => 2);
$verified = 1;
$response = $sailthruClient->setEmail($email, $vars, $lists, $templates, $verified);
//Get Blast information
$blast_id = 52424;
$response = $sailthruClient->getBlast($blast_id);
//schedule blast
$blast_name = 'test_blast1';
$list = 'default';
$schedule_time = '+1 days';
$from_name = 'Prajwal Tuladhar';
$from_email = '[email protected]';
$subject = "Hey what's up!";
$content_html = "<b>Lorem ipsum dolor si</b>";
$content_text = strip_tags($content_html);
$response = $sailthruClient->scheduleBlast($blast_name, $list, $schedule_time, $from_name, $from_email, $subject, $content_html, $content_text);
//schedule blast from template
$template = 'default';
$list = 'default';
$schedule_time = 'now';
$options = array();
#$response = $sailthruClient->scheduleBlastFromTemplate($template, $list, $schedule_time, $options);
//schedule blast from previous blast
//Note: if blast_id is invalid, request won't work
$_blast_id = '110065';
$_schedule_time = 'now';
$_options = array(
'vars' => array(
'my_var' => '3y6366546363',
'my_var2' => array(7,8,9),
'my_var3' => array('president' => 'obama', 'nested' => array('vp' => 'palin'))),
);
$response = $sailthruClient->scheduleBlastFromBlast($_blast_id, $_schedule_time, $_options);
//update blast
$blast_id = 46513;
$blast_name = 'test_blast88';
$response = $sailthruClient->updateBlast($blast_id, $blast_name, $list, $schedule_time, $from_name, $from_email, $subject, $content_html, $content_text);
//cancel scheduled blast
$response = $sailthruClient->cancelBlast($blast_id);
//delete blast
$response = $sailthruClient->deleteBlast($blast_id);
//get metadata for all lists
$lists_metadata = $sailthruClient->getLists();
//download a list
$list = 'default';
$response = $sailthruClient->getList($list, "txt");
//saves /updates a list
$emails = '[email protected], [email protected]';
$response = $sailthruClient->saveList($list, $emails);
//delete a list
$response = $sailthruClient->deleteList($list);
//get meta-data of all exisiting templates
$response = $sailthruClient->getTemplates();
//get information of a given template
$template = 'welcome-template';
$response = $sailthruClient->getTemplate($template);
//get information of a template from it's revision id
$revision_id = 45204;
$response = $sailthruClient->getTemplateFromRevision($revision_id);
//create new template or update existing one
$template = 'new-template';
$options = array(
'from_name' => 'Sailthru Support',
'from_email' => '[email protected]',
'content_html' => '<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 qu</p>',
'subject' => 'Sailthru Support'
);
$response = $sailthruClient->saveTemplate($template, $options);
//save template from existing revision id
$template = 'welcome-template';
$revision_id = 45204;
$response = $sailthruClient->saveTemplateFromRevision($template, $revision_id);
//delete existing template
$template = 'welcome-template';
$response = $sailthruClient->deleteTemplate($template);
//import contacts
$response = $sailthruClient->importContacts('[email protected]', "your-super-secret-password-which-we-will-never-store");
//push content
$title = 'hello world';
$url = 'http://example.com/product-url';
$response = $sailthruClient->pushContent($title, $url);
//another push content example
$title = 'hello world';
$url = 'http://example.com/product-url';
$date = null;
$tags = array("blue", "red", "green");
$vars = array('vars' => array('price' => 17299));
$response = $sailthruClient->pushContent($title, $url, $date, $tags, $vars);
//Retrieve a user's alert settings.
$email = '[email protected]';
$response = $sailthruClient->getAlert($email);
//saves an alert for a user
$email = '[email protected]';
$alert_type = 'realtime';
$options = array(
'match' => array(
'type' => array(
'shoes', 'shirts'
)
),
'min' => array(
'price' => 3000
),
'tags' => array('blue', 'red')
);
$when = null;
$template = 'my-template';
$response = $sailthruClient->saveAlert($email, $alert_type, $template, $when, $options);
//deletes an alert
$email = '[email protected]';
$alert_id = '4d463bad6763d90e0e000581';
$response = $sailthruClient->deleteAlert($email, $alert_id);
//post purchase
$email = '[email protected]';
$items = array(
array('id' => 11, 'price' => 26262, 'qty' => '11', 'url' => 'http://example.com/234/high-impact-water-bottle', 'title' => 'High-Impact Water Bottle'),
array('id' => 171, 'price' => 262, 'qty' => '18', 'url' => 'http://xyz.com/abc', 'title' => 'some title2')
);
$response = $sailthruClient->purchase($email, $items);
//post purchase incomplete request
$email = '[email protected]';
$items = array(
array('id' => 11, 'price' => 26262, 'qty' => '11', 'url' => 'http://example.com/234/high-impact-water-bottle', 'title' => 'High-Impact Water Bottle'),
array('id' => 171, 'price' => 262, 'qty' => '18', 'url' => 'http://xyz.com/abc', 'title' => 'some title2')
);
$message_id = '23423.231';
$response = $sailthruClient->purchaseIncomplete($email, $items, $message_id);
//get list stats
$response = $sailthruClient->stats_list();
//get blast stats
$blast_id = 6752;
$response = $sailthruClient->stats_blast($blast_id);
//gets horizon data for a user
$email = ''[email protected];
$hid_only = false;
$response = $sailthruClient->getHorizon($email, $hid_only);
//sets horizon user data
$email = '[email protected]';
$tags = array('blue', 'red', 'green');
$response = $sailthruClient->setHorizon($email, $tags);
//set horizon cookie
$email = '[email protected]';
$sailthruClient->setHorizonCookie($email);
//get the status of a job
$job_id = '4dd58f036803fa3b5500000b';
$response = $sailthruClient->getJobStatus($job_id);
# process import job for email string
$list = 'test-list';
$emails = '[email protected],[email protected]';
$response = $sailthruClient->processImportJob($list, $emails);
# process import job from CSV or text file
$list = 'test-list';
$source_file = '/home/praj/Desktop/emails.txt';
$response = $sailthruClient->processImportJobFromFile($list, $source_file);
# process snapshot job
$query = array();
$report_email = '[email protected]';
$postback_url = 'http://example.com/reports/snapshot_postback';
response = $sailthruClient->processSnapshotJob($query);
# process export list job
$list = 'test-list';
$response = $sailthruClient->processExportListJob($list);
# process update job from emails CSV
$emails = "[email protected],[email protected]";
$update = array(
'lists' => array('sailthru-list' => 1),
'vars' => array('location' => 'New York, NY')
);
$response = $sailthruClient->processUpdateJobFromEmails($emails, $update);
//recieve verify post
$sailthruClient->receiveVerifyPost();
//recieve optout post
$sailthruClient->receiveOptoutPost();