Skip to content
This repository was archived by the owner on Mar 3, 2023. It is now read-only.

Example application which receives EasyPost Tracker webhook and sends notifications to customers.

Notifications You must be signed in to change notification settings

EasyPost/example-tracking-notifications

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 

EasyPost Tracking Notification Examples

The EasyPost Tracking API makes it simple to get EasyPost tracking updates with webhooks. These example applications show some creative ways to update you (and your customers) with the latest information on their shipments!

Example: Sending SMS Tracking Notifications

/sms_tracking

This example application uses Flask, the EasyPost Python client, and the Twilio API to send a formatted SMS message to a customer after a tracking event occurs on their shipment.

Try this demo on your computer!

Download the contents of this repository and use a shell to navigate to sms_tracking/. Make sure you have Python and pip installed.

Since you're going to be using a test Tracker and sending SMS messages, you'll need your test API key from EasyPost (which you can find here) and an account SID, auth token, and phone number from Twilio. To receive webhooks from EasyPost locally, you'll need to install ngrok.

Run $ pip install -r requirements.txt to install Flask, the EasyPost Python client, and the Twilio Python library.

Rename config-example.py to config.py, and replace the placeholders with your API authorization keys. Replace SMS_TO_NUMBER with a number of a cell phone that can receive SMS messages.

It's time to start the app! Run $ python sms_tracking.py, then run $ ngrok http 12345 in another shell to expose the app publicly through ngrok. Ngrok will give you a URL that looks something like https://xxxxxxxx.ngrok.io; copy it. This is the webhook URL that EasyPost will send an update to when the fake "package" has a tracker event. We need to let EasyPost know about this URL, so we'll create a new webhook with cURL:

$ curl -X POST easypost.com/api/v2/webhooks -d 'webhook[url]=http://xxxxxxxx.ngrok.io/easypost-webhook&webhook[mode]=test' -u 'your-test-api-key:'

(Replace "xxxxxxxx.ngrok.io" with the ngrok URL you copied, and fill in your actual EasyPost test API key).

It's showtime! EasyPost will send us a webhook after we create a test Tracker. We use a test tracking code, "EZ2000000002" (you can find the full list of test tracking codes here):

$ curl -X POST https://easypost.com/v2/trackers -d 'tracker[tracking_code]=EZ2000000002' -u 'your-test-api-key:'

Soon, you should get a customized SMS message when a shipment update occurs on the test Tracker. Awesome!

Ideas for production-ready apps

While this app isn't ready for production quite yet, it's a great example of what you can do with the EasyPost Tracking API. Here are some ideas for how you could extend this application:

You could:

  • Notify customers if the shipment is delayed or has deliverability issues
  • Alert customers with the name of the person that signed for their package
  • Let a customer know when their package enters their home state, or is out for delivery
  • Send email notifications in addition to SMS messages

Unit tests

$ python sms_tracking_tests.py

Example: Sending Email Tracking Notifications

/email_tracking

This example application uses Sinatra, the EasyPost Ruby client, and the SendGrid API to send a formatted SMS message to a customer after a tracking event occurs on their shipment.

Try this demo on your computer!

Download the contents of this repository and use a shell to navigate to email_tracking/. Make sure you have the following requirements.

Requirements

  1. A Windows or Mac computer running Ruby Bundler
  2. An EasyPost account
  3. A SendGrid account

Since you're going to be using a test Tracker and sending Emails, you'll need your test API key from EasyPost (which you can find here) and an API key from SendGrid. To receive webhooks from EasyPost locally, you'll need to install ngrok.

Run $ bundle install to install Sinatra, the EasyPost Ruby client, and the SendGrid Ruby library.

Rename sample.env to .env, and replace the placeholders with your API authorization keys.

It's time to start the app! Run $ ruby app.py, then run $ ./ngrok http 4567 in another shell to expose the app publicly through ngrok. Ngrok will give you a URL that looks something like https://xxxxxxxx.ngrok.io; copy it. This is the webhook URL that EasyPost will send an update to when the fake "package" has a tracker event. We need to let EasyPost know about this URL, so we'll create a new webhook with cURL:

$ curl -X POST easypost.com/api/v2/webhooks -d 'webhook[url]=http://xxxxxxxx.ngrok.io/easypost-webhook&webhook[mode]=test' -u 'your-test-api-key:'

(Replace "xxxxxxxx.ngrok.io" with the ngrok URL you copied, and fill in your actual EasyPost test API key).

It's showtime! EasyPost will send us a webhook after we create a test Tracker. We use a test tracking code, "EZ2000000002" (you can find the full list of test tracking codes here):

$ curl -X POST https://easypost.com/v2/trackers -d 'tracker[tracking_code]=EZ2000000002' -u 'your-test-api-key:'

Soon, you should get a customized EMAIL when a shipment update occurs on the test Tracker.

About

Example application which receives EasyPost Tracker webhook and sends notifications to customers.

Resources

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 5