Webhooks
Good practice
On this page
A few habits make a webhook receiver reliable and safe.
Handle repeats (idempotent handling)#
- The same event can arrive more than once, for example when your reply was slow and a retry was sent, or when someone presses Redeliver. Keep the
idof every event you have handled and ignore anidyou have seen. - Events can arrive out of order. For the current state, use the object in
data, or call the API for the latest version, instead of assuming order. - Make your handler safe to run twice: for example "set the order status to packed" rather than "add one to a counter".
- Reply with 2xx once the event is safely saved (for example in a queue), then do the slow work.
- Expect new things: a later update can add fields to
data, and an endpoint that listens to all events receives events that did not exist when you wrote your code. Ignore fields and event types you do not know, and still answer 2xx.
Test it#
- Ask the store's owner (a Super Admin) to press Send test event on the endpoint in the admin and choose an event, or do it with them. The message has
"test": trueand made-up data, and it is signed like a real one. - The delivery log shows what your endpoint answered, so you can see why a delivery failed.
- Check your signature code against the test value first.
- The address must be on the public internet. Addresses such as localhost are refused, so test on a public test server.
Keep it safe#
- Check the signature and the time of every message, and answer 400 when either fails.
- Use an https address.
- Keep the signing secret out of your code repository. If it may have leaked, rotate it: the old one keeps signing for 24 hours so you can switch over.
- Switch off personal details for endpoints that do not need them.
- Never log or publish the raw body of order or contact messages: they can contain customers' details.
Zapier and Make#
Important
A native Zapier or Make app is not built. There is no GroKeeper app to pick inside them. You use their general webhook tools together with the API. These steps have not been run against a live Zapier account, so try them with Send test event first.
- In Zapier use Webhooks by Zapier with Catch Hook and copy the address it shows into a new webhook endpoint. In Make use the Webhooks and HTTP modules. Check that Webhooks by Zapier is available to your Zapier account.
- Zapier cannot check the signature itself. The long secret address is what keeps the Zap private: do not share it.
- To act on your store (for example mark an order shipped) use an HTTP request with an API key and an
Idempotency-Key: see the API reference.