Skip to content

uniquelyparticular/shipengine-request

Repository files navigation

@particular./shipengine-request

npm version semantic-release code style: prettier CircleCI dependency status: david

🎮 Minimal ShipEngine API request library for Node

Installation

yarn add @particular./shipengine-request # npm install @particular./shipengine-request

Quickstart (implicit)

const { createClient } = require('@particular./shipengine-request');
// import { createClient } from '@particular./shipengine-request'

const shipEngine = new createClient({
  client_secret: '...'
});

shipEngine
  .delete('tags/:tag_name')
  .then(console.log)
  .catch(console.error);

shipEngine
  .get('carriers')
  .then(console.log)
  .catch(console.error);

shipEngine
  .patch('insurance/shipsurance/add_funds', {
    currency: 'usd',
    amount: 10.0
  })
  .then(console.log)
  .catch(console.error);

shipEngine
  .post('rates', {
    shipment_id: 'se-123',
    rate_options: {
      carrier_ids: ['se-123890']
    }
  })
  .then(console.log)
  .catch(console.error);

shipEngine
  .put('shipments/:shipment_id', {
    validate_address: 'no_validation',
    shipment_id: 'se-202902255',
    carrier_id: 'se-123890',
    service_code: 'usps_priority_mail',
    external_shipment_id: '6801bdc2-ed1d-472f-8108-fcc3c163a172',
    ship_date: '2019-04-11T05:00:00.000Z',
    created_at: '2019-04-11T19:09:29.151Z',
    modified_at: '2019-04-11T19:09:29.151Z',
    shipment_status: 'pending',
    ship_to: {
      name: 'Mickey and Minnie Mouse',
      phone: '714-781-4565',
      company_name: 'The Walt Disney Company',
      address_line1: '500 S BUENA VISTA ST',
      address_line2: '',
      city_locality: 'BURBANK',
      state_province: 'CA',
      postal_code: '91521-0001',
      country_code: 'US'
    },
    // ...
    insurance_provider: 'none',
    tags: [],
    packages: [
      {
        weight: {
          value: 9.6,
          unit: 'ounce'
        },
        dimensions: {
          unit: 'inch',
          length: 12.0,
          width: 7.1,
          height: 6.0
        },
        insured_value: {
          currency: 'usd',
          amount: 0.0
        }
      }
    ]
  })
  .then(console.log)
  .catch(console.error);

Kitchen sink

const { createClient } = require('@particular./shipengine-request');

const shipEngine = new createClient({
  client_secret: '...',
  host: '...',
  version: '...',
  application: '...',
  currency: '...',
  headers: {
    // ...
  }
});

Custom headers per request

The API provides you the ability to send various request headers that change the way data is stored or retrieved.

By default this library will encode all data as JSON, however you can customise this by setting your own Content-Type header as an additional argument to get, patch, post, put and delete.

Note: If you add the Content-Type custom header to patch, post, put or delete you will need to encode data yourself.

const { createClient } = require('@particular./shipengine-request');

const shipEngine = new createClient({
  client_secret: '...'
});

const headers = {
  'X-ShipEngine-Currency': 'gbp'
};

shipEngine
  .get('carriers', headers)
  .then(console.log)
  .catch(console.error);

Contact Adam Grohs @ Particular. for any questions.