Socket
Socket
Sign inDemoInstall

sparkpost

Package Overview
Dependencies
Maintainers
4
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sparkpost

A Node.js wrapper for interfacing with your favorite SparkPost APIs


Version published
Weekly downloads
22K
increased by1.98%
Maintainers
4
Weekly downloads
 
Created
Source

Travis CI

SparkPost Build by MessageSystems

Node.js SDK

The official Node.js binding for your favorite SparkPost APIs!

Prerequisites

Before using this library, you must have:

Installation

npm install sparkpost

Initialization

new SparkPost(apiKey, options) - Initialization

  • apiKey
    • Required: yes (unless key is stored in SPARKPOST_API_KEY environment variable)
    • Type: String
    • a passed in apiKey will take precedence over an environment variable
  • options.origin or options.endpoint
    • Required: no
    • Type: String
    • Default: https://api.sparkpost.com:443
  • options.apiVersion
    • Required: no
    • Type: String
    • Default: v1
  • options.headers
    • Required: no
    • Type: Object
    • set headers that apply to all requests

Methods

  • request(options, callback)
    • options - see request modules options
    • options.uri - can either be a full url or a path that is appended to options.origin used at initialization (url.resolve)
    • callback - executed after task is completed. required
      • standard callback(err, data)
      • err - any error that occurred
      • data.res - full response from request client
      • data.body - payload from response
  • get | post | put | delete(options, callback)
    • options - see request options
    • callback - see request options
    • Request method will be overwritten and set to the same value as the name of these methods.

Creating a SparkPost Client

Passing in an API key

var SparkPost = require('sparkpost');
var client = new SparkPost('YOUR_API_KEY');

Using an API key stored in an environment variable

process.env.SPARKPOST_API_KEY = 'YOUR_API_KEY';
var SparkPost = require('sparkpost');
var client = new SparkPost();

Specifying non-default options

var SparkPost = require('sparkpost');
var options = {
  endpoint: 'https://dev.sparkpost.com:443'
};
var client = new SparkPost('YOUR_API_KEY', options);

Using the Node SDK Base Object

We may not wrap every resource available in the SparkPost SDK, for example the Node SDK does not wrap the Metrics resource, but you can use the Node SDK Base Object to form requests to these unwrapped resources. Here is an example request using the base object to make requests to the Metrics resource. Here is an example request using the base object to make requests to the Metrics resource.

// Get a list of domains that the Metrics API contains data on.
var options = {
  uri: 'metrics/domains'
};

client.get(options, function(err, data) {
  if(err) {
    console.log(err);
    return;
  }

  console.log(data.body);
});

SparkPost API Resources Supported in Node SDK

Click on the desired API to see usage and more information

Development

Setup

We use Grunt for our task runner, so you will also have to install Grunt globally npm install -g grunt-cli

Run npm install inside the repository to install all the dev dependencies.

Testing

Once all the dependencies are installed, you can execute the unit tests using grunt test

Contributing

Guidelines for adding issues

Our coding standards

Submitting pull requests

FAQs

Package last updated on 12 May 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