Receive real-time notifications when email events occur
Webhooks send HTTP POST requests to your server when events occur—deliveries, bounces, opens, clicks, and more. Instead of polling the API, get notified instantly.
Use metadata for correlation: The metadata object contains the custom key-value pairs you attached when sending the email. Use it to look up related records in your database.
class ArkWebhooksController < ApplicationController skip_before_action :verify_authenticity_token def create # 1. Verify signature (see Security page for full implementation) verify_signature! event = JSON.parse(request.body.read) # 2. Idempotency: skip if already processed return head :ok if already_processed?(event['uuid']) mark_as_processed!(event['uuid']) # 3. Process event (queue to background job for production) process_event(event) # 4. Return 200 quickly head :ok rescue => e head :unauthorized end private def already_processed?(uuid) Rails.cache.exist?("ark_webhook:#{uuid}") end def mark_as_processed!(uuid) Rails.cache.write("ark_webhook:#{uuid}", true, expires_in: 24.hours) end def process_event(event) case event['event'] when 'MessageSent' # Update delivery status when 'MessageBounced', 'MessageDeliveryFailed' # Handle bounce - consider adding to suppression list when 'MessageLoaded' # Track open end endend