Setting Up Webhooks
ShipEngine allows you to subscribe to webhooks to receive real-time updates for long-running asynchronous operations. This is useful because it allows your application to move on to other work while the operation is running rather than being blocked until it completes.
It also allows ShipEngine to push updates to your application rather than having your application continually poll for updates.
For example, you may subscribe to the track
webhook event to automatically receive an update anytime a tracking event occurs.
Rather than continually sending a request to the /v1/labels/:label_id/track
endpoint to see if the tracking information has been
updated since the last time you checked, you can subscribe to the track
webhook event and ShipEngine will push the notification
to your application via a webhook whenever the tracking details are updated.
If you're new to webhooks, you can read this guide for more information.
Configuring Webhooks
Before you can begin receiving webhooks, you must configure your ShipEngine account with the HTTP endpoints you'd like for the webhooks to be sent to. You can do this through the ShipEngine Dashboard or through the API.
Configure Using the Dashboard
- Log in to the ShipEngine Dashboard.
- Go to Developer, then Webhooks.
- Click the Add New Webhook button.
- Select your Webhook Event and enter your Webhook URL. You can set up multiple URLs for the same Event.
- Click the green checkmark icon to save your webhook.
Configure Using the API
To configure a webhook using the API, you'll need to provide a url
and an event
that will trigger the webhook.
You'll send this data in an HTTP POST request to /v1/environments/webhooks
.
You may only configure one URL per event.
The payload for each type of webhook event will have a unique resource_type
which indicates which type of event triggered the webhook.
The event
names you use in your payload when you configure a webhook through the API as well as the corresponding resource_type
that will be sent in the webhook request for that event are listed below.
Description | event | resource_type |
---|---|---|
Batch completed | batch | API_BATCH |
Shipment rate updated | rate | API_RATE |
Any tracking event | track | API_TRACK |
Carrier connected | carrier_connected | API_CARRIER_CONNECTED |
Sales Orders imported (Beta) | sales_orders_imported | API_SALES_ORDERS_IMPORTED |
Order Source refresh complete (Beta) | order_source_refresh_complete | API_ORDER_SOURCE_REFRESH_COMPLETE |
A requested report is ready | report_complete | API_REPORT_COMPLETE |
Example Request
Testing Webhooks
You can use a service like requestbin.com to create temporary URLs to test webhooks. Any HTTP requests sent to that endpoint will be recorded with the associated payload and headers so you can observe the data sent from our webhooks before configuring your application to accept it.
Webhook Payloads
These are example payloads for the types of webhooks you can subscribe to. You can expect to receive a message with the same structure
as these examples whenever you subscribe to the corresponding event. You'll notice that each payload includes a resource_type
and
a resource_url
. Some payloads will contain additional information as well.