Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Sailthru PHP5 Client

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 sailthru
Octocat-spinner-32 tests
Octocat-spinner-32 .gitignore
Octocat-spinner-32 CHANGELOG.md
Octocat-spinner-32 MIT-LICENSE
Octocat-spinner-32 README.md
Octocat-spinner-32 phpunit.xml
Octocat-spinner-32 run_tests.sh
README.md

sailthru-php5-client

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:

Examples

Constructor

$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

//send
$response = $sailthruClient->send('temlate-name', 'praj@sailthru.com', array('name' => 'unix'), array('test' => 1));

//multi send
$response = $sailthruClient->multisend('default', 'abc@xyz.com,praj@sailthru.com', array('name' => 'unix'), array(), array('test' => 1));

//get send
$response = $sailthruClient->getSend("TUMVqWdj2exnAAV-");

//cancel send
$response = $sailthruClient->cancelSend("TUMYT2dj2fl1AABD");

email

//get email information of a user
$response = $sailthruClient->getEmail("praj@sailthru.com");

//update user info
$email = 'praj@sailthru.com';
$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);

blast

//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 = 'praj@sailthru.com';
$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);

list

//get metadata for all lists
$lists_metadata = $sailthruClient->getLists();

//download a list
$list = 'default';
$response = $sailthruClient->getList($list, "txt");

//saves /updates a list
$emails = 'more@abc.com, less@xyz.com';
$response = $sailthruClient->saveList($list, $emails);

//delete a list
$response = $sailthruClient->deleteList($list);

template

//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' => 'support@sailthru.com',
'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);

contacts

//import contacts
$response = $sailthruClient->importContacts('some-email@gmail.com', "your-super-secret-password-which-we-will-never-store");

content

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

alert

//Retrieve a user's alert settings.
$email = 'praj@sailthru.com';
$response = $sailthruClient->getAlert($email);

//saves an alert for a user
$email = 'praj@sailthru.com';
$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 = 'praj@sailthru.com';
$alert_id = '4d463bad6763d90e0e000581';
$response = $sailthruClient->deleteAlert($email, $alert_id);

purchase

//post purchase
$email = 'praj@sailthru.com';
$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 = 'praj@sailthru.com';
$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);

stats

//get list stats
$response = $sailthruClient->stats_list();

//get blast stats
$blast_id = 6752;
$response = $sailthruClient->stats_blast($blast_id);

horizon

//gets horizon data for a user
$email = ''praj@sailthru.com;
$hid_only = false;
$response = $sailthruClient->getHorizon($email, $hid_only);

//sets horizon user data
$email = 'praj@sailthru.com';
$tags = array('blue', 'red', 'green');
$response = $sailthruClient->setHorizon($email, $tags);

//set horizon cookie
$email = 'praj@sailthru.com';
$sailthruClient->setHorizonCookie($email);

job

//get the status of a job
$job_id = '4dd58f036803fa3b5500000b';
$response = $sailthruClient->getJobStatus($job_id);

# process import job for email string
$list = 'test-list';
$emails = 'a@a.com,b@b.com';
$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 = 'praj@sailthru.com';
$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 = "praj@sailthru.com,ian@sailthru.com";
$update = array(
'lists' => array('sailthru-list' => 1),
'vars' => array('location' => 'New York, NY')
);
$response = $sailthruClient->processUpdateJobFromEmails($emails, $update);

postbacks

//recieve verify post
$sailthruClient->receiveVerifyPost();

//recieve optout post
$sailthruClient->receiveOptoutPost();
Something went wrong with that request. Please try again.