0.0.3 • Published 6 years ago

parcelmonkey v0.0.3

Weekly downloads
1
License
ISC
Repository
-
Last release
6 years ago

ParcelMonkey Node.js Client

Get quotes and create shipments from your Node.js applications

npm JavaScript Style Guide

Requirements

A user ID and API key from your account at https://www.parcelmonkey.co.uk/apiSettings.php

Install

npm i parcelmonkey

Connect to ParcelMonkey

const ParcelMonkey = require('parcelmonkey')

let options = {
  host: 'api.parcelmonkey.co.uk',
  port: 443,
  userId: '<your user id>',
  apiKey: '<your API Key>'
}

let pm = new ParcelMonkey(options)

Create a Box

ParcelMonkey.Box arguments:

  • length: box length, in centimetres
  • width: box width, in centimetres
  • height: box height, in centimetres
  • weight: box weight, in kilograms
let box = new ParcelMonkey.Box(22.8, 14.6, 14.8, 1.1)

Create Sender and Recipient

let sender = new ParcelMonkey.Sender({
  name: 'Parcel Monkey',
  phone: '',
  email: '',
  address1: '',
  address2: '',
  town: 'London',
  county: 'London',
  country: 'GB',
  postcode: ''
})

let recipient = new ParcelMonkey.Recipient({
  name: 'Nicola',
  phone: '01234567890',
  email: 'nicola@example.com',
  address1: 'Hilton Midtown',
  address2: '1335 6th Avenue',
  town: 'New York',
  county: 'NY',
  country: 'US',
  postcode: '10019'
})

Get shipping quotes

pm.getQuote({
  sender,
  recipient,
  boxes: [box],  // array of boxes
  value: 20      // value in £
}).then(quotes => {
  console.log(quotes)

  // Select a record returned from `getQuote` to pass as the `quote` argument to `createShipment`.
  let quote = quotes[0]
})

Create a shipment

pm.createShipment({
  quote,
  sender,
  recipient,
  boxes: [box],
  value: 20,
  description: 'My shipment of things',
  collectionDate: '2018-11-07'
}).then(result => {
  console.log('SHIPMENT :', result)
}).catch(err => {
  console.log('SHIPMENT ERROR :', err)
})
0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago