Manage webhooks

Webhooks allow 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 send update notifications as POST requests to a URL that you supply. These requests include not only the updated field value, but all the key field values of the resource being updated.

Webhooks are often used for:

  • Deploying a static website when content is changed.
  • Syncing data to an external search engine platform.
  • Update legacy databases.
  • Triggering notifications in apps.

Event types

The events below can be used to trigger a webhook notification. Depending on your plan some options may not be available.

Type
content_item.published
content_item.unpublished
content_item.created
content_item.changed
content_item.deleted
asset.created
asset.changed
asset.deleted
segment.created
segment.changed
segment.deleted

Create a webhook

Follow the guidelines below to successfully create a webhook endpoint.

You need to set up your callback endpoint before you can create a webhook in Prepr. The endpoint must use HTTPS and be able to receive both GET and POST requests. All notifications will be sent as POST requests and include a JSON payload with Prepr headers and custom headers, if defined in the webhook.

Configure your webhook URL

  1. Log in to your Prepr account with a user that has Owner, Admin or Developer rights.
  2. Go to Settings > Webhooks.
  3. Create a new webhook by clicking the Add webhook button. Enter the URL of the endpoint where the notifications will be sent.

Create webhook

  1. Select the events that will trigger the request and click the Save and close button.

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.

Filter events by model

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.

Add custom headers

Response

View the full list of notifications sent to your webhook on the Webhook detail page in your Prepr account. From here you can view the response the Prepr server received from your endpoint.

Webhook response

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.

Retry behavior

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.

Disable behaviour

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.

View attempts

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.

Webhook response

Resend webhooks

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.

Performance Requirements

Respond to all webhook events in 12 seconds or less. After 12 seconds the notification is considered failed and will be retried.

Security guidelines

We recommend to protect the endpoints to which we'll send 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.

87.233.165.0/26
2001:9a8:0:4b:: 64 bits

Webhook Signatures

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.

Verifying signatures
The Prepr-Signature header contains the full json payload you receive.

Prepr generates signatures using a hash-based message authentication code (HMAC) with SHA-256.

Compute an 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 the 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.