Webhooks
Get notified when a screenshot has been rendered.
Webhooks allow your application to receive information when a render, such as a screenshot, has been generated. This allows you to request renders asynchronously.
Using webhooks
Pass a webhook URL in as the webhook_url
option and Urlbox will send a POST
request to that URL with data about the render once it has completed rendering, or an error has occurred.
This will result in a response like the following being POSTed to https://example.com/webhooks/urlbox
once the render is complete:
If there is an error during rendering, an example webhook payload will look similar to:
Webhooks are often used in combination with our S3-compatible storage making it easy for you to gather large numbers of screenshots asynchronously.
Verify Webhook
In order to verify that the webhook is being sent by Urlbox, you can use the X-Urlbox-Signature
header sent with the webhook.
You will require your webhook secret, which you can find in the Urlbox dashboard in the project settings.
The webhook signature is sent in the form t={timestamp},sha256={token}
.
Your code should extract the timestamp
and token
values from the received header.
You should then generate a HMAC-SHA256 of the timestamp value appended with a full-stop (period i.e. '.' ), which is then appended to the JSON stringified body of the webhook request body:
{timestamp}.{JSON stringified webhook payload}
Example
For example, let's say the webhook payload you received was:
and the timestamp is 1705016013
,
then the timestamp value appended with a full-stop (period i.e. '.' ) and with the JSON stringified webhook payload would look like:
We then create a HMAC-SHA256 token of the above string using your webhook secret as the key:
(This example is using nodejs, but every language will have equivalent functionality to create a HMAC-SHA256 token)
Now we can compare the token we have generated, with the token embedded in the X-Urlbox-Signature
header.
If they match, we know that the request has been legitimately sent from Urlbox.
Command Line
If you need a way to test your own token generation code, you can generate a HMAC-SHA256 on the command line with the following command:
This token would match the X-Urlbox-Signature header's token: