Skip to content

Instantly share code, notes, and snippets.

@mootrichard
Created June 20, 2017 17:22
Show Gist options
  • Save mootrichard/4557ff32ffbf127f6d8449aac7e6020b to your computer and use it in GitHub Desktop.
Save mootrichard/4557ff32ffbf127f6d8449aac7e6020b to your computer and use it in GitHub Desktop.
4 Ways to Improve Post-Purchase Experience
const shippo = require('shippo')('YOUR_SHIPPO_API_KEY');
let addressObject = {
name: "Shawn Ippotle",
company: "Shippo",
street1: "218 Claytona St.",
city: "San Francisco",
state: "CA",
zip: "94117",
country: "US",
phone: "+1 555 341 9393",
email: "shippotle@goshippo.com",
validate: true
};
shippo.address
.create(addressObject)
.then((response)=>{
// Do actions with the validated address
console.log(JSON.stringify(response, null, 2));
});
const shippo = require('shippo')('YOUR_SHIPPO_API_KEY');
let addressTo = {
name: "Shawn Ippotle",
company: "Shippo",
street1: "218 Claytona St.",
city: "San Francisco",
state: "CA",
zip: "94117",
country: "US",
phone: "+1 555 341 9393",
email: "shippotle@goshippo.com"
}
let addressFrom = {
name: "Mrs Hippo",
street1: "1092 Indian Summer Ct",
city: "San Jose",
state: "CA",
zip: "95122",
country: "US",
phone: "4159876543",
email: "mrshippo@goshippo.com"
}
let parcels = [
{
length: "5",
width: "5",
height: "5",
distance_unit: "in",
weight: "2",
mass_unit: "lb"
}
]
let shipmentObject = {
address_from: addressFrom,
address_to: addressTo,
parcels: parcels,
async: false
};
shippo.shipment
.create(shipmentObject)
.then((response)=>{
// You now have an array of all your rates available for that shipment.
let rates = response.rates;
// You can send those to the front-end to display, filter them, or even
// adjust a small inflation on that rate before returning it to the user
// to account for handling fees or other costs you might incure from
// shipping
console.log(JSON.stringify(rates, null, 2));
});
const shippo = require('shippo')('YOUR_SHIPPO_API_KEY');
var webhookData = {
carrier: "usps",
tracking_number: "1122334455667788",
metadata: "test order"
}
shippo.track
.create(webhookData)
.then((response)=>{
// You'll be returned back the initial status of your shipment
console.log(JSON.stringify(response,null ,2));
});
const shippo = require('shippo')('YOUR_SHIPPO_API_KEY');
let addressTo = {
name: "Shawn Ippotle",
company: "Shippo",
street1: "218 Clayton St.",
city: "San Francisco",
state: "CA",
zip: "94117",
country: "US",
phone: "+1 555 341 9393",
email: "shippotle@goshippo.com"
}
let addressFrom = {
name: "Shippo Returns Dept",
company: "Shippo Returns",
street1: "965 Mission Street",
street2: "Suite 480",
city: "San Francisco",
state: "CA",
zip: "94103",
country: "US",
phone: "+1 555 341 9393",
email: "returns@goshippo.com"
}
let parcels = [
{
length: "5",
width: "5",
height: "5",
distance_unit: "in",
weight: "2",
mass_unit: "lb"
}
]
let shipmentObject = {
address_from: addressFrom,
address_to: addressTo,
parcels: parcels,
extra: {
is_return: true
},
async: false
};
shippo.shipment
.create(shipmentObject)
.then((response)=>{
console.log(JSON.stringify(response, null, 2));
}, (err)=>{
console.error(err);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment