Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sailthru-client

Package Overview
Dependencies
Maintainers
3
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sailthru-client

Node.js client for Sailthru API

  • 2.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7.7K
increased by8.65%
Maintainers
3
Weekly downloads
 
Created
Source

sailthru-node-client

For installation instructions, documentation, and examples please visit: http://getstarted.sailthru.com/new-for-developers-overview/api-client-library/node-js-npm

A simple client library to remotely access the Sailthru REST API as per http://getstarted.sailthru.com/new-for-developers-overview/api/api-overview/

By default, it will make request in JSON format. XML format is not supported.

Development

npm install # to install dependencies locally
npm install -g coffee-script # to install coffee-script
cake test # for running tests
cake build # for building and generating JavaScript source
cake watch # for watching file changes

Installation

npm install sailthru-client

Examples

Initialization

var apiKey = '******',
    apiSecret = '*****',
    sailthru = require('sailthru-client').createSailthruClient(apiKey, apiSecret);

Getting version

var version = require('sailthru-client').VERSION;

Enable / Disable Logging

sailthru.enableLogging();
sailthru.disableLogging();

Making POST Request

var data = {
    email: 'foo@example.com',
    lists: {
        'list-a': 1
    }
};
sailthru.apiPost('email', data, function(err, response) {
    if (!err) {
        console.log(response);
    } else {
        console.log('Error!');
        console.log(err);
    }
});

Making POST Request with multipart (Eg: Job API call with import type)

// Making import /job API POST call
// MUltipart call
var data = {
    job: 'import',
    list: 'test-list',
    file: './emails.txt'
};
var multipart_params = ['file']; // this is required to mark file as a multipart upload item'
sailthru.apiPost('job', data, function(err, response) {
   console.log(response);
}, multipart_params);

Making GET Request

// Making /send API GET call
var send_id = 'TE8EZ3-LmosnAgAA';
sailthru.apiGet('send', {send_id: send_id}, function(err, response) {
    console.log(response);
});

Making DELETE Request

// /send API DELETE call
var send_id = 'TE8EZ3-LmosnAgAA';
sailthru.apiDelete('send', {send_id: send_id}, function(err, response) {
    console.log(response);
});

send

//send
var template = 'my-template',
    email = 'foo@example.com',
    options = {
        'vars': {
            'name': 'Foo Bar',
            'address': 'Queens, NY'
        },
        'options': {
            'test': 1,
            'replyto': 'bar@example.com'
        }
    };
sailthru.send(template, email, function(err, response) {
    if (err) {
        console.log("Status Code: " + err.statusCode);
        console.log("Error Code: " + err.error);
        console.log("Error Message: " + err.errormsg);
    } else {
        //process output
    }
}, options);

//multi-send
var emails = ['blah@example.com', 'foo@example.com', 'bar@example.com'],
    template = 'multi-template',
    options = {
        'options': {
            'test': 1
        }
    };
sailthru.multiSend(template, emails, options, function(err, response) {
    if (err) {
        //Process error
    } else {
        //process JSON output
    }
});

FAQs

Package last updated on 06 Oct 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc