BlogRSS Feed

Andrew Tribone

How Do Package Tracking Webhooks Work?

by Andrew Tribone
Webhook icon

Webhooks are custom "callbacks" (or scheduled/triggered executions of code) that are used to send notifications from one application to another. You may know them as push notifications

We use webhooks to provide our customers with tracking notifications. Since carriers don’t offer any kind of support for push notifications today, EasyPost does the work to filter relevant updates from the carrier and notify you. So instead of constantly polling the carrier for information, you only get notified of updates that matter to you.

In our Tracking API, you can use webhook URLs that act as receivers to our events. These events can then be mapped to certain behaviors in your own application. For instance, if we send an event for a Tracker with a status of out_for_delivery, you can map that event to an action within your application, e.g. sending an email update to your customer or updating the database record for the package.

Our client libraries make it easy to integrate webhooks into your current application. The following is an example of a Ruby Sinatra application to consume out_for_deliery events and send an email.

require 'json'
require 'sinatra'

post '/easypost-webhook' do
  event = EasyPost::Event.receive(JSON.parse(request.body.read))

  if event.result.object == "Tracker" && event.result.status == "out_for_delivery"
    send_email(event.result.tracking_code)
  end
end

def send_email(tracking_code)
  # send an email to your customer
end

This gives you total freedom on how you want to use our webhooks, which underlines our entire ethos. Our webhooks - like our API - are tools to improve how you currently do business. There is no one-size-fits-all program that can magically fix your shipping woes. What you can do is tailor a perfect solution that fits your business, which is what we want to help you accomplish.