- Where
- Console, Developers (Webhooks)
- Who can do it
- Owners
- Plans
- Webhooks is included in Growth, Scale and Enterprise
In detail
Webhooks save you from asking the API over and over whether anything has changed. Your system is told within seconds of a scan, a delivery or an invoice.
Adding an endpoint
- Choose Add webhook on the Developers screen.
- Enter the endpoint address. It must use https; plain http is accepted only for localhost while you develop. Addresses with a user name or password in them are refused, and so are private network addresses outside development.
- Choose the events, or choose all of them, which also includes any event added later.
- Save, then copy the signing secret shown. Store it on your server: it is how you prove that a message came from us. See verify webhook signatures.
A workspace can have up to 20 endpoints. Each sender account can add up to 5 of its own in the sender portal, which hear only about that sender's parcels.
The events
| Event | Sent when |
|---|---|
| shipment.created | A delivery is booked in the console, the sender portal or through the API. |
| shipment.collected | The parcel is scanned as collected from the sender. |
| shipment.at_hub | The parcel is scanned in at a location. |
| shipment.out_for_delivery | The driver starts the run that carries the parcel. |
| shipment.nearby | The vehicle comes close to the delivery address. |
| shipment.delivered | The driver records proof of delivery. |
| shipment.failed | The driver records that the delivery could not be made. |
| shipment.rescheduled | Staff or the recipient move the delivery to another window. |
| shipment.returned | A return to sender is arranged. |
| shipment.cancelled | The booking is cancelled before the parcel goes out. |
| run.started, run.finished | A driver leaves on a run, or completes it. |
| exception.opened, exception.resolved | Something needs a person's attention, or has been dealt with. |
| cod.collected | A driver takes payment at the door. |
| return.requested | A return is requested for a delivered parcel. |
| invoice.issued | An invoice is issued to a sender account. |
How a delivery is made
Each event is a POST with a JSON body and these headers: X-YallaRoute-Event (the event name), X-YallaRoute-Delivery (the delivery number, also shown in the delivery log) and X-YallaRoute-Signature. Endpoints on the current body format also get X-YallaRoute-Version, naming that format. The body carries the event's id, its type, the time it happened and its data. Redirects are not followed, so give the final address.
If your endpoint does not answer 2xx within 6 seconds, the delivery is tried again after 30 seconds, 2 minutes, 10 minutes and 1 hour, then marked failed. Retries go out while the server is busy with other requests, so on a quiet workspace one can be a little later than planned.
Testing, pausing and sending again
- Send a test event: posts a signed example of any event and shows the answer. The example is marked
"test": true. Test events are sent even while the endpoint is paused. - Pause an endpoint to stop deliveries without losing its settings, and resume it later.
- Send again any past delivery from the delivery log. It goes as a new delivery with the same event and data.
Writing a good receiver
- Check the signature before doing anything else.
- Answer 2xx quickly and do the work afterwards, so a slow job never causes a retry.
- Store the ids of events you have handled and skip repeats: a retry can deliver the same event twice.
- Do not rely on order. Two events about one parcel can arrive either way round; compare their times.