Webhooks allows your app to receive notifications whenever there are updates to a chosen set of events.
For example, you could set up a webhook for the
content_item.created event and subscribe to be notified whenever a new
Content item is created.
Webhooks update notifications are sent as POST requests to a URL that you supply. Notifications include the newly updated value, as well as the base resource.
Webhooks are often used for:
- Deploying a static website when content is changed.
- Syncing data to a external search engine platform.
- Update legacy databases.
- Triggering notifications in apps.
The events below can be used to trigger a webhook notification. Depending on your plan some options may not be available.
A list containing all notifications send to your webhook van be found on the Webhook detail page in your Prepr account. Attempts can be viewed and retried. You can also view the response the Prepr server received from your endpoint.
Setting up an endpoint
Follow the guidelines below to successfully create a webhook endpoint.
You need to set up your callback endpoint before you can set up a subscription. The endpoint
HTTPS and be able to receive both
POST requests. All notifications will be
POST requests for now and include a
JSON payload and Custom + Prepr headers to verify.
Configuring your webhook URL
Log-in to your Prepr account with a user that has owner, admin or developer rights.
Go to Settings > Webhooks.
Create a new webhook by clicking 'Add webhook'. Enter the URL, the notifications will be sent to an optionally custom headers to protect you endpoint.
Select the events you want the webhook to be notified about and click 'Save'.
Filter events on the content model
When you have selected a content item event, you will receive notifications when a content item is created, (un)published, changed, or deleted. You can further specify which content items you want to receive notifications from. Select one or more models to receive webhook events for content items of that specific model. Selecting none will act as a wildcard.
Add custom headers
There are some use-cases where an application requires some fields to be added in the header of the webhook payload. The most common headers are access tokens or a personal scope key. To add a custom header, enter a header key and value.
Your endpoint should return a
2xx HTTPS response for all notifications. When other status codes are returned
the notification is considered failed and will be retried.
If your webhook continues to fail for multiple times in 24 hours, your webhook will be disabled. The account owner will be notified in such event.
Prepr attempts multiple times to deliver a given notification to your webhook endpoint with an exponential back off. You can configure a maximum number of retries. If your endpoint has been disabled you can still expect to see future retry attempts.
Prepr will actively notify the owner of the environment when the webhook is misconfigured or the error rate is 100%. The email also states when the endpoint will be automatically disabled.
To manage an existing webhook, go to Settings > Webhooks and click the specific webhook in the list. All attempts of this webhook of the last three days can be viewed and retried here. You can also view the response the Prepr server received from your endpoint.
You can resend a webhook event by clicking the resend button.
Switch off webhook
You can easily switch off your webhook temporarily. Go to the detail page of your webhook and disable the 'status' option.
Respond to all webhook events in 12 seconds or less. After 12 seconds the notification is considered failed and will be retried.
We recommend to protect the endpoints to which we will sent the notifications. This prevents unauthorized actions on your app.
When configuring your webhook in Prepr, add an Authorization header with a secret access token only your incoming webhook server knows.
Prepr will send all of the custom headers you added when sending a notification, including Authorization. If the values don't match, you can ignore the request.
Whitelisting Prepr Server IPs
You can ensure your app is always communicating with Prepr through one of our IP addresses.
22.214.171.124/26 2001:9a8:0:4b:: 64 bits
Prepr will sign the webhook events it sends to your endpoints. We do so by
including a signature in each event’s
Prepr-Signature header. This allows
you to validate that the events were sent by Prepr, not by a third party.
Before you can verify signatures, you need to store your endpoint’s id when creating a new Webhook. Each id is unique to the endpoint to which it corresponds. If you use multiple endpoints, you must obtain a id for each one.
Prepr-Signature header contains the full json payload you receive.
Prepr generates signatures using a hash-based message authentication code (HMAC) with SHA-256.
HMAC with the
SHA256 hash function. Use the endpoint’s signing id
as the key, and use the json payload string as the message.
Compare the signature in the header to the expected signature. If a signature matches, compute the difference between the current timestamp and the received timestamp, then decide if the difference is within your tolerance.
To protect against timing attacks, use a constant-time string comparison to compare the expected signature to each of the received signatures.
Preventing replay attacks
A replay attack is when an attacker intercepts a valid payload and its signature,
then re-transmits them. To mitigate such attacks, Prepr includes a timestamp in
Prepr-Signature header. Because this timestamp is part of the signed payload,
it is also verified by the signature, so an attacker cannot change the timestamp
without invalidating the signature. If the signature is valid but the timestamp is too old,
you can have your application reject the payload.
We recommend a tolerance of five minutes between the timestamp and the current time. We advise that you use Network Time Protocol (NTP) to ensure that your server’s clock is accurate and synchronizes with the time on Prepr's servers.
Prepr generates the timestamp and signature each time we send an event to your endpoint. If Prepr retries an event (e.g., your endpoint previously replied with a non-2xx status code), then we generate a new signature and timestamp for the next delivery attempt.