Webhooks
Use webhooks to get notified when something happens in Campsite
Webhooks allow your integration to receive real-time notifications about events in Campsite, like a new post or comment being created. When an event occurs, Campsite sends an HTTP POST request to the URL you specify, allowing your integration to take action based on the event data.
Creating a webhook
To add a webhook to your integration:
- Go to your Organization settings and click the Integrations tab.
- Select your integration from the list, or create an integration if you don’t have one.
- In the Webhooks section of your integration settings, click Add webhook.
- Enter the HTTPS URL where you want to receive webhook events.
- Click Create webhook to save.
Webhook guidelines
- HTTPS is required for all webhook URLs.
- Webhook events are guaranteed to be delivered once. You may use the id field in the payload as an idempotency key.
- Your webhook consumer should respond with a 2xx HTTP response status code to indicate a successful delivery. Any other response status code indicates a failed delivery. Campsite will retry failed deliveries up to 10 times.
- Implement proper error handling in your webhook consumer to avoid processing the same event multiple times.
- Respond quickly to webhook requests (within 20 seconds) to avoid timeouts. If you need to perform time-consuming operations, acknowledge the webhook quickly and process the event asynchronously.
Webhook payload
Webhook payloads are sent as JSON in the body of the POST request. Here’s an example payload for a post.created
event:
Supported events
Currently, these are supported:
post.created
: Triggered when a new post is created.comment.created
: Triggered when a new comment is created.app.mentioned
: Triggered when your integration is @-mentioned in a post or comment.
The data object in the payload will contain information about the respective entity (post or comment) that triggered the event.
Webhook signature verification
Campsite signs outbound requests using a shared secret key. To verify that an incoming webhook is genuinely from Campsite:
- After creating a webhook, click Copy secret to get your webhook’s secret key.
- Use this secret to validate the signature in the X-Campsite-Signature header of incoming webhook requests.
The X-Campsite-Signature header has the following format:
To verify the signature:
- Split the header value by comma to separate the timestamp and signature.
- Construct the signed payload by concatenating the timestamp, a period (.), and the request body.
- Compute an HMAC with the SHA256 hash function, using your webhook secret as the key and the signed payload as the message.
- Compare your computed signature with the v1 signature in the header.
Here’s a TypeScript example of how to verify the signature: