Webhooks allows your app to easily receive notifications whenever there are updates to a chosen set of events.
For example, you could set up a webhook for the
publication.created event and subscribe to be notified whenever a new
Publication 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 (Notify) notifications in apps.
There are 11 events that can trigger a Webhook notification.
A list containing all notifications send to you 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.
Setting up an 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 -> Development -> Webhooks.
Create a new Webhook by clicking 'Add webhook'. Enter the URL the notifications will be sent to and optionally custom headers to protect you endpoint.
Select the events you want the webhook to be notified about and click 'Save'.
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.
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.
18.104.22.168/28 22.214.171.124/26 126.96.36.199/29 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 recieve.
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.