Quickstart: receive and deliver a webhook
Create a source and a destination, connect them, send a webhook, and read how it was delivered.
This quickstart creates a source for payment webhooks, a destination in your app, and a connection between them. Then it sends a webhook to the source and reads how it was delivered.
Before you begin
- Set up your environment, so
HOOKS_API_KEYandHOOKS_URLare set. - Have an HTTPS address in your app that answers
POSTrequests with a 2xx status. This quickstart useshttps://shop.example.com/webhooks/payments.
Receive and deliver a webhook
Create a source
curl -X POST "$HOOKS_URL/sources" \ -H "Authorization: Bearer $HOOKS_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "name": "Payments" }'The answer holds the new source. Its
urlis the address senders send webhooks to. Copy itsidandurlinto variables:export SOURCE_ID="the-source-id" export SOURCE_URL="the-source-url"Create a destination
curl -X POST "$HOOKS_URL/destinations" \ -H "Authorization: Bearer $HOOKS_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "name": "Shop", "url": "https://shop.example.com/webhooks/payments" }'Copy the new destination’s
id:export DESTINATION_ID="the-destination-id"Connect them
curl -X POST "$HOOKS_URL/connections" \ -H "Authorization: Bearer $HOOKS_API_KEY" \ -H "Content-Type: application/json" \ -d "{ \"sourceId\": \"$SOURCE_ID\", \"destinationId\": \"$DESTINATION_ID\" }"From now on, every webhook the source receives is delivered to the destination.
Send a webhook
Send a webhook to the source, as a payment service would. No API key is needed:
curl -X POST "$SOURCE_URL" \ -H "Content-Type: application/json" \ -d '{ "reference": "ORD-104233", "amount": 25000, "msisdn": "255745123456", "status": "COMPLETED" }'The source answers
200with{"status":"received"}. The webhook is kept from this moment.Read the delivery
List the destination’s deliveries. The newest is first:
curl "$HOOKS_URL/deliveries?destination=$DESTINATION_ID" \ -H "Authorization: Bearer $HOOKS_API_KEY"When your app answered with a 2xx status, the delivery’s
statusisdelivered. If it isretryingorfailed,lastErrorClassandlastErrorsay why. See View events and deliveries.
Clean up
Delete the source if you do not want it to keep receiving webhooks. This deletes its connections and its events too, and cannot be undone:
curl -X DELETE "$HOOKS_URL/sources/$SOURCE_ID" \
-H "Authorization: Bearer $HOOKS_API_KEY"What’s next
- Verify deliveries to your app, so your app accepts only webhooks we delivered.
- Filter and delay webhooks, to send each destination only what it needs.
- Change webhooks before they are sent.
Last updated