๐ Getting Started
To start receiving webhook events from Flock in your application, follow these steps:- Create a webhook endpoint: Build an endpoint in your application to receive event data via HTTPS POST requests. This endpoint should be capable of processing JSON payloads.
- Register your webhook endpoint: Log in to your Flock account at app.withflock.com, navigate to the Webhooks page, and add your endpoint.
- Handle multiple events: You can configure your endpoint to receive multiple event types or create separate endpoints for specific events, depending on your needs.
- Locate your webhook secret: After registering your endpoint, you can find the webhook secret key in your Flock account under the Secrets page. This key is required for verifying the authenticity of webhook requests.
- Secure your endpoint: Use the webhook secret to implement signature verification. This ensures that the payloads are genuinely from Flock and protects your endpoint from unauthorized requests.
๐ Secure Your Webhook Endpoint
To ensure that the event payloads sent to your webhook endpoint are legitimate and untampered, Flock includes a digital signature in theX-Flock-Signature header and a timestamp in the payload body of each webhook request. Follow these steps to verify the signature:
Step 1: Extract the Timestamp and Signature from the Request
When your endpoint receives a webhook event, the signature is sent in theX-Flock-Signature header, and the timestamp is included in the JSON payload body.
Example header and payload:
Header:
request
Step 2: Verify the Signature and Validate the Timestamp
To verify the signature and validate the timestamp, use the shared secret from the Secrets page in your Flock account. This ensures that the payloads are genuinely from Flock and protects against replay attacks by checking that the timestamp is within an acceptable range (e.g., 5 minutes from the current time).Step 3: React to the Webhook Events
By implementing a webhook endpoint, you can react to events likeinvitee.accepted to send notifications to proper parties or even trigger your custom rewards.
Step 4: Implement a Retry Mechanism
Flock does not retry sending events if your webhook endpoint fails to acknowledge them. To ensure no events are missed, we recommend you implement a retry mechanism to handle errors or downtime in your systems, allowing you to reprocess events if needed.Step 5: Respond to Flock
After verifying the signature and processing the payload, respond with a200 OK status.
Webhook Payload
Payload Structure
When Flock sends a webhook event to your endpoint, the payload will have the following structure:Event Names
Flock can send the following webhook events:Campaign Events
Customer Events
Referral Events
Reward Events
Registering for Events
You can register webhooks for specific events in the Flock dashboard. You can create multiple webhook endpoints, each listening for different events, or a single endpoint that handles all events.For security reasons, always verify the signature of incoming webhook events as described in the โSecure Your Webhook Endpointโ section above.