Blog Atom Feed

Jack Lawson

Node.js SDK v3.0.0 RC

by Jack Lawson
Node.js Logo

EasyPost has a new version of the Node.js SDK covering all documented endpoints. The API remains similar, with the exception that all requests are now promise-based. In addition, the SDK has been fully documented in the API Documentation and examples have been added to the Getting Started guides. You can install the new version using npm install --save node-easypost@3.0.0-rc.1.

Here's an example of using the API to create an address:

const apiKey = 'cueqNZUb3ldeWTNX7MU3Mel8UXtaAMUi';
const EasyPost = require('node-easypost');

const api = new EasyPost(apiKey);

const fromAddress = new api.Address({
  name: 'EasyPost',
  street1: '118 2nd Street',
  street2: '4th Floor',
  city: 'San Francisco',
  state: 'CA',
  zip: '94105',
  phone: '415-123-4567'
});

/* es5 with promises: */
fromAddress.save().then(addr => {
  console.log(addr.id);
});

/* es2017 with async/await: */
async function create (addr) => {
  const address = new api.Address(addr);

  try {
    await address.save();
  } catch (e) {
    console.error(e);
  }
}

create(fromAddress);

Available endpoints include Addresses, Parcels, Reports, Shipments, Trackers, Insurance, Batches, Customs Infos and Customs Items, Events, Fees, Orders, Pickups, API Keys, Child Users, Carrier Types, and Carrier Accounts.

All of the code is written in ES6, compiled down to ES5 for NPM, and is available on GitHub.