Last active
April 14, 2017 17:19
-
-
Save mootrichard/3d3022e3b2d80b968324ab2f5c4c3d61 to your computer and use it in GitHub Desktop.
An example of posting to Shippo's webhook using Node.JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"carrier": "ups", | |
"tracking_number": "92748931507953573000007541", | |
"address_from": null, | |
"address_to": null, | |
"eta": null, | |
"servicelevel": { | |
"token": null, | |
"name": null | |
}, | |
"metadata": null, | |
"tracking_status": null, | |
"tracking_history": [] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"carrier": "usps", | |
"tracking_number": "92748931507953573000007541", | |
"address_from": { | |
"city": "New Braunfels", | |
"state": "TX", | |
"zip": "78130", | |
"country": "US" | |
}, | |
"address_to": { | |
"city": "New Braunfels", | |
"state": "TX", | |
"zip": "78130", | |
"country": "US" | |
}, | |
"eta": "2017-01-25T00:00:00Z", | |
"servicelevel": { | |
"token": null, | |
"name": null | |
}, | |
"metadata": null, | |
"tracking_status": { | |
"object_created": "2017-03-28T00:02:28.161Z", | |
"object_updated": "2017-03-28T00:02:28.161Z", | |
"object_id": "b78f190f63af483ca41ba818eded502f", | |
"status": "DELIVERED", | |
"status_details": "Your shipment has been delivered at the front door.", | |
"status_date": "2017-01-25T13:39:00Z", | |
"location": { | |
"city": "New Braunfels", | |
"state": "TX", | |
"zip": "78130", | |
"country": "US" | |
} | |
}, | |
"tracking_history": [ | |
{ | |
"object_created": "2017-01-24T14:58:53.499Z", | |
"object_id": "8d4338436f2049cc987082cbf2d7484a", | |
"status": "UNKNOWN", | |
"status_details": "The USPS has received the electronic shipment information and is awaiting the item.", | |
"status_date": "2017-01-23T00:00:00Z", | |
"location": null | |
}, | |
{ | |
"object_created": "2017-01-24T22:11:06.368Z", | |
"object_id": "294fd37ef58f432da899f1edebeef2e2", | |
"status": "TRANSIT", | |
"status_details": "Your shipment has been accepted at the USPS destination facility.", | |
"status_date": "2017-01-24T14:05:00Z", | |
"location": { | |
"city": "New Braunfels", | |
"state": "TX", | |
"zip": "78130", | |
"country": "US" | |
} | |
}, | |
{ | |
"object_created": "2017-01-24T22:11:06.368Z", | |
"object_id": "92a4c161131846cfa542709093cd0545", | |
"status": "TRANSIT", | |
"status_details": "Your shipment has arrived at the post office.", | |
"status_date": "2017-01-24T15:20:00Z", | |
"location": { | |
"city": "New Braunfels", | |
"state": "TX", | |
"zip": "78130", | |
"country": "US" | |
} | |
}, | |
{ | |
"object_created": "2017-03-28T00:02:28.161Z", | |
"object_id": "09afa08021184b03ad89b0dbbed130dc", | |
"status": "TRANSIT", | |
"status_details": "Your shipment has been sorted completely.", | |
"status_date": "2017-01-25T09:50:00Z", | |
"location": { | |
"city": "New Braunfels", | |
"state": "TX", | |
"zip": "78130", | |
"country": "US" | |
} | |
}, | |
{ | |
"object_created": "2017-03-28T00:02:28.161Z", | |
"object_id": "b21dc93509804bf3bf81c01f67e60b44", | |
"status": "TRANSIT", | |
"status_details": "Your shipment is out for delivery.", | |
"status_date": "2017-01-25T10:00:00Z", | |
"location": { | |
"city": "New Braunfels", | |
"state": "TX", | |
"zip": "78130", | |
"country": "US" | |
} | |
}, | |
{ | |
"object_created": "2017-03-28T00:02:28.161Z", | |
"object_id": "77115a714b7a4d05845006173245e7d0", | |
"status": "DELIVERED", | |
"status_details": "Your shipment has been delivered at the front door.", | |
"status_date": "2017-01-25T13:39:00Z", | |
"location": { | |
"city": "New Braunfels", | |
"state": "TX", | |
"zip": "78130", | |
"country": "US" | |
} | |
} | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const https = require('https'); | |
const shippoToken = 'YOUR_SHIPPO_API_TOKEN' // Replace with your token | |
let postOptions = { | |
host: 'api.goshippo.com', | |
port: 443, | |
path: '/tracks/', | |
method: 'POST', | |
headers: { | |
'Authorization': `ShippoToken ${shippoToken}`, | |
'Content-Type': 'application/json' | |
} | |
}; | |
const postReq = https.request(postOptions, (res)=>{ | |
res.setEncoding('utf8'); | |
res.on('data', (chunk)=>{ | |
console.log('Body: ' + chunk); | |
}) | |
}); | |
let trackingCarrier = 'usps'; | |
let trackingNumber = '9205590164917312751089'; | |
let additionalMetaData = '1-555-555-5555'; | |
let postData = { | |
'carrier': `${trackingCarrier}`, | |
'tracking_number': `${trackingNumber}`, | |
'metadata': `${additionalMetaData}` | |
} | |
postReq.write(JSON.stringify(postData)); | |
postReq.end(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const shippo = require('shippo')('YOUR_SHIPPO_API_TOKEN'); | |
let trackingCarrier = 'usps'; | |
let trackingNumber = '9205590164917312751089'; | |
let additionalMetaData = '1-555-555-5555'; | |
let postData = { | |
'carrier': `${trackingCarrier}`, | |
'tracking_number': `${trackingNumber}`, | |
'metadata': `${additionalMetaData}` | |
} | |
shippo.track.create(postData).then((results)=>{ | |
console.log('Success: ' + JSON.stringify(results, null , 4)); | |
}, (error)=>{ | |
console.log('Error: ' + error); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment