@agnostack/aftership-request

Please contact agnoStack via info@agnostack.com for any questions

Usage no npm install needed!

<script type="module">
  import agnostackAftershipRequest from 'https://cdn.skypack.dev/@agnostack/aftership-request';
</script>

README

@agnostack/aftership-request

🎮 Minimal AfterShip API request library for Node

Installation

yarn add @agnostack/aftership-request # npm install @agnostack/aftership-request

Quickstart (OAuth)

const { createClient } = require('@agnostack/aftership-request');
// import { createClient } from '@agnostack/aftership-request'

const aftership = new createClient({
  api_key: '...' // AfterShip API key.
});

aftership
  .get('couriers')
  .then(console.log)
  .catch(console.error);

aftership
  .post('trackings', {
    tracking: {
      tracking_number: 'RA123456789HK',
      slug: 'usps'
    }
  })
  .then(console.log)
  .catch(console.error);

aftership
  .put('trackings/:slug/:tracking_number', {
    tracking: {
      title: 'New Title'
    }
  })
  .then(console.log)
  .catch(console.error);

Kitchen sink

const aftership = new createClient({
  api_key: '...',
  api_domain: '...',
  version: 'v4',
  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, post, put and delete.

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

const aftership = new createClient({
  api_key: '...'
});

const headers = {
  'X-My-Header': 'custom'
};

aftership
  .get('couriers', headers)
  .then(console.log)
  .catch(console.error);

Contact Adam Grohs @ agnoStack for any questions.