Skip to main content
Your app often needs to react when something happens to a sandbox. You might want to show “ready” in your interface, bill a user when their session ends, alert someone when a sandbox crashes, or deploy when an image build finishes. You could ask Fibre about every sandbox over and over (this is called polling), but that is slow and wasteful. Webhooks turn this around: Fibre tells you. You give Fibre the address of an endpoint on your server, once. From then on, whenever something happens, Fibre sends a POST request to that address describing the event. Each request is signed so you can check it really came from Fibre, it is retried until your server accepts it, and every delivery is recorded.

Events

These are the events Fibre can send you: Every request has a JSON body with the same shape:
body
It also carries three headers:

Verify the signature

Your endpoint is reachable from the internet, so anyone could send it a request that looks like a Fibre event. Always check the signature before trusting a webhook. Here is how it works. When you create the webhook, Fibre gives you a secret that only you and Fibre know. For each request, Fibre computes an HMAC-SHA256 of the timestamp, a dot, and the raw body ("<t>.<body>"), using that secret as the key, and puts the result in the Fibre-Signature header. Your server computes the same value with its copy of the secret. If the two match, the request is genuine. Checking the timestamp too protects you against someone replaying an old request. Here is a complete handler in TypeScript and in Python:
TypeScript (Express)
Python (Flask)
Compute the signature over the raw body, exactly as it arrived. If you parse the JSON first and convert it back to text, the bytes change and the signature will not match. In Express, use express.raw() on this route, as shown above.

Try it end to end

You can see real deliveries without deploying anything, because a sandbox has a public address and can act as your receiver. This small receiver checks each request’s signature and writes down what arrived.
1

Start a receiver

curl: the receiver program
2

Register the webhook

Now tell Fibre where to send events. events chooses which events you want; leave it out to receive all of them. The answer includes the secret, and this is the only time you will see it, so store it where your server can read it. Here, it is written to a file in the receiver.
response
The real answer also includes secret, which is left out above.
3

Send a test, and cause a real event

A test sends a ping event to your endpoint straight away. To see real events as well, start a sandbox and then delete it: that sends sandbox.ready and then sandbox.deleted.
output
Every delivery arrived, and every signature was valid.

Retries

Your endpoint must answer with a 2xx status within 10 seconds. Anything else counts as a failure: an error status, no answer in time, or a refused connection. After a failure, Fibre tries again, waiting longer each time: Every attempt for the same event carries the same Fibre-Event-Id. Fibre guarantees that each event arrives at least once, but occasionally it may arrive twice, for example if your 200 answer was lost on its way back. So remember the IDs you have handled, and skip an event you have already processed.
Answer first, and do the work afterwards. Save the event and return 200 immediately, then do the slow part (sending emails, billing, deploying) in a background job. If your handler takes longer than 10 seconds, Fibre treats it as a failure and sends the event again, even though your handler did its job.

See what was delivered

When something goes wrong, it helps to see what Fibre sent and how your server replied. You can list an endpoint’s last 50 deliveries, newest first:
response
A delivery’s status is pending (waiting for its next attempt), succeeded, or failed (every attempt has been used). last_error says what went wrong, such as HTTP 500 or a timeout.

Rotate the secret

If you think a secret may have leaked, replace it with a new one. The old secret keeps working for 24 hours alongside the new one, so you have time to update your server without missing a single event. During those 24 hours, Fibre-Signature carries two v1= values, one for each secret, and a match with either one is enough.

Delete

To stop receiving events at an endpoint, delete it:

Good to know

A few limits and rules:

Sleep and wake

Understand what sandbox.ready with restored, and sandbox.stopped, tell you.

Images and builds

build.succeeded tells you an image is ready to run.