Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

lob

lob26.9kMIT6.6.3

Lob API wrapper

Lob, Lob-node, rest, api, wrapper, Lob.com, printing

readme

lob-node

NPM version Downloads Build Status Dependency Status Dev Dependency Status Coverage Status

Node.js wrapper for the Lob.com API. See full Lob.com documentation here.


Starting a new project, we recommend using our TypeScript SDK!

Move your existing project from lob-node to lob-typescript-sdk? Checkout this migration guide.


Table of Contents

Getting Started

Here's a general overview of the Lob services available, click through to read more.

Please read through the official API Documentation to get a complete sense of what to expect from each endpoint.

Registration

First, you will need to first create an account at Lob.com and obtain your Test and Live API Keys.

Once you have created an account, you can access your API Keys from the Settings Panel.

Installation

lob-node can be installed through the npm:

$ npm install lob

To build and install from the latest source:

$ git clone git@github.com:lob/lob-node.git
$ npm install

Usage

const Lob = require('lob')('YOUR API KEY');

// change api version
const Lob = require('lob')('YOUR API KEY', { apiVersion: 'API-VERSION' });

// change internal defaults (e.g. host)
const options = {/* see options below */};
const Lob = require('lob')('YOUR API KEY', options);

// you can also just pass options
const options = { apiKey: 'foo', host: 'bar' };
const Lob = require('lob')(options);

// callback pattern
Lob.addresses.list((err, body) => {
  if (err) return callback(err);
  return callback(null, body.data);
});

Additionally, every resource method returns a promise, so you don't have to use the regular callback. E.g.

const Lob = require('lob')('YOUR API KEY');

Lob.addresses.list()
.then((res) => {
  console.log(res.data);
})
.catch((e) => {
  console.log(e);
});

Options

The Lob constructor accepts an options object which may contain one or more of the following options:

  • apiVersion - Optionally set the version of the Lob API to use. Defaults to latest.
  • host - Override the default host API calls are issued to.
  • userAgent - Override the default userAgent.
  • headers - Edit the headers sent in all API calls.
  • agent - Override the default HTTP agent used to make requests.

Examples

We've provided various examples for you to try out here.

There are simple scripts to demonstrate how to create all the core Lob objects (checks, letters, postcards. etc.) as well as more complex examples that utilize other libraries and external files.

Accessing Response Headers

You can access response headers via a hidden _response property.

Lob.addresses.list()
.then((res) => {
  res._response.headers['content-type'];
  // => "application/json; charset=utf-8"
});

You can also access headers from errors.

Lob.addresses.retrieve('adr_bad_id')
.catch((err) => {
  err._response.headers['content-type'];
  // => "application/json; charset=utf-8"
});

API Documentation

The full and comprehensive documentation of Lob's APIs is available here.

Contributing

To contribute, please see the CONTRIBUTING.md file.

Testing

To run the tests with coverage:

LOB_API_KEY=YOUR_TEST_API_KEY npm test

To run the tests without coverage:

LOB_API_KEY=YOUR_TEST_API_KEY npm run test-no-cover

=======================

Copyright © 2013 Lob.com

Released under the MIT License, which can be found in the repository in LICENSE.txt.

changelog

6.6.3 (2022-08-24)

Features
  • campaigns add support for campaigns endpoint (PR_275)
Maintenance
  • bump mocha from 9.1.3 to 10.0.0
  • bump eslint-config-lob from 1.0.1 to 5.2.0

6.6.2 (2022-04-11)

Maintenance
  • bump minimist from 1.2.0 to 1.2.6
  • bump moment from 2.29.1 to 2.29.2

6.6.1 (2022-04-05)

Maintenance
  • autocomplete add query param for address casing
  • Update dependency version
  • Updates to CI process
  • Updates to Repo branch naming

6.5.5 (2022-01-14)

Maintenance
  • Removed Bluebird dependency and replaced with p-map
  • Updated 4 out of date dev dependencies
  • Updated min required version of NodeJS to 10
  • Removed package-lock.json from gitignore - it is now included in the repo.

6.5.3 (2022-01-04)

Features
  • templates add support for HTML templates endpoint (PR_258)

6.5.2 (2021-10-18)

Bug Fix
  • cards: adds card update route to expose cards update endpoint in SDK. (PR_256) (6870842)

6.5.1 (2021-10-14)

Bug Fix
  • card orders: updates the card orders "quantity_ordered" field to "quantity" in the integration test & example to reflect the recent change in Lob API endpoint for creating card orders. (PR_254) (9d3a261)

6.5.0 (2021-10-13)

Features
  • cards: add support for cards endpoint (PR_252) (e744da5)
  • card_orders: add support for card orders endpoint (PR_252) (35bc050)
  • examples: add examples for creating a card and card order (PR_252) (1c41494)

6.4.0 (2021-09-21)

New Features
  • us_verifications: Reverse Geocoding endpoint (#250) (ea1e49df)
  • examples: added a bunch of examples which WERE in the old docs (#249) (bba10957)

6.3.0 (2021-08-27)

6.2.1 (2021-07-28)

Chores

6.2.0 (2021-05-03)

New Features
  • self-mailers: Add support for Self Mailers (#236)
Chores
Bug Fixes
  • README: correct Bank Accounts documentation link (#234) (f7f7609d)

6.1.1 (2020-11-06)

Bug Fixes
  • merge-variables: convert merge variables to JSON (#232) (5352dea7)

6.1.0 (2020-04-15)

Chores
New Features
  • resource: add ability to specify custom HTTP agent (#224) (bf925b1c)
Bug Fixes
  • intl-verifications: fixed failing test (#219) (f2b712ad)
Tests
  • plc: add tests for new versions (template syntax and cursor pagination) (#226) (d5806217)

6.0.6 (2019-07-19)

Chores

6.0.5 (2019-02-14)

Chores
  • lib: fixed npm scripts on windows, moved from istanbul to nyc (#213) (be91922d)

6.0.4 (2019-01-30)

New Features
  • postcards: add ability to modify concurrency (4a3bbf37)
Bug Fixes
  • resource-base: handle undefined multipart form value (#212) (711261dc)

6.0.3 (2019-1-7)

Chores
Tests
  • api-key:
    • remove lob api key from tests and examples (93fee77a)
    • remove lob api key from tests and examples (062022b3)

6.0.2 (2018-12-3)

Bug Fixes
  • resource-base: default body to empty object (70f9c804)
  • deps:
    • upgrade rest of vulnerable deps (3b84d7e0)
    • upgrade mocha (and growl) version (95bdf700)
  • addresses: fix broken test (#202) (e560d6bc)

6.0.1 (2018-8-7)

Bug Fixes
  • headers: don't save request specific headers in configs (#201) (cfa0fb19)

6.0.0 (2018-07-02)

New Features
  • area-mail: remove areas and routes resources (a17d234d)

5.3.0 (2018-05-21)

New Features
  • us-autocompletions: add USAutocompletions (b64b02db)
Bug Fixes
  • readme: replace dependency status badge and upgrade vulnerable deps (#198) (b758c76d)

5.2.0 (2018-3-13)

New Features
  • us-verifications: allow passing queries in verification creation (#197) (84b9a44a)

5.1.0 (2018-02-22)

Refactors

5.0.0 (2017-12-11)

Chores
  • lib:
  • deprecate: Deprecate support for 0.10 and 0.12 (#187) (bd0130d3)
Bug Fixes
  • test: fix US verification test (a0f10925)
  • auto-verify: update tests to manage auto-verify (107eeae3)
Other Changes
  • postcards: Remove message field from postcard (c298fe4c)
Refactors
  • object: Use Object.prototype.call, instead of assuming objects inherit from Object.prototype (#191) (8648cb0c)
Tests
  • intl: Update international verifications tests (5f38b3d3)

4.1.1 (2017-08-09)

Chores
  • examples:
    • update to use merge_variables (cc6c2d3c)
    • Fix examples to use new us_verifications endpoint (b6096944)
New Features
  • idempotency-key: Add optional headers argument to create() methods to support idempotency-key (99ef7e92)
  • us-zip-lookups: Add US Zip Code Lookup (d51e8c8b)
  • delete: Add delete method to postcards, letters, and checks chore(ignore): ignore Sublime files (aa340b57)
Bug Fixes
  • readme: update documentation (73afa906)

4.1.1 (2017-08-09)

Chores
  • examples:
    • update to use merge_variables (cc6c2d3c)
    • Fix examples to use new us_verifications endpoint (b6096944)
New Features
  • idempotency-key: Add optional headers argument to create() methods to support idempotency-key (99ef7e92)
  • us-zip-lookups: Add US Zip Code Lookup (d51e8c8b)
  • delete: Add delete method to postcards, letters, and checks chore(ignore): ignore Sublime files (aa340b57)
Bug Fixes
  • readme: update documentation (73afa906)

4.0.0 (2017-5-17)

Chores
  • mock: use mock.lob.com (1fed1c75)
  • jobs: removes jobs, objects, settings endpoints (bbfd446e)
Documentation Changes
  • contributing: changed out-of-date link to valid (96e21cff)
New Features
  • verifications: add us and intl verification endpoints ENG-2769 (13f5ed8c)
  • version: support Node versions 0.12, 4, 5, and 6. (7754b22f)
Bug Fixes

3.9.0 (2016-4-15)

New Features
  • response: allow access to response headers (3c4d6514)
  • api-version: support 2016-03-21 (a304c9cf)

3.8.0 (2016-2-2)

Chores
  • release: add release scripts (7cc243eb)
New Features
  • version: support api version 2016-01-19 (6cb6cec0)
  • bank-accounts: standardize verify function (1d0b37c2)
  • deps: remove gulp (a2c164a7)
Bug Fixes
  • errors: always throw Error object (41c88f97)
  • readme: update testing instructions (f193cb0a)
Tests
  • resources: standardize and remove unnecessary tests (ad0e45ed)
  • setup: use global expect, api key, Lob (6e44ce0b)

2.6.2