Subscribe to events from an event store
POST /api/event-stores/{eventStoreName}/subscribe
Creates a subscription to receive events from a specific event store.
Events will be delivered to the configured destination whenever new events matching your filter pattern are appended to streams in the event store.
Duplicate Detection
For webhook subscriptions, the system will automatically detect if a subscription with the same configuration already exists (same URL, headers, timeout, and event filter). If found, the existing subscription will be returned instead of creating a duplicate. This helps prevent accidentally creating multiple subscriptions for the same webhook endpoint.
Event Filtering
Events can be filtered using pattern matching:
*- Match ALL event typesnamespace.*- Match all events in a namespace (e.g.,user.*matchesuser.created,user.updated, etc.)*.event- Match all events of a specific type across namespaces (e.g.,*.createdmatchesuser.created,order.created, etc.)namespace.event- Match a specific event type exactly (e.g.,user.created)
Subscriber Types
Events can be delivered to several destination types:
- Durable Object: Events are delivered to a Durable Object instance via its
handlemethod - Webhook: Events are sent as HTTP POST requests to a specified URL
- Queue: Events are sent to a Cloudflare Queue
- Cloudflare Workflow: Events trigger a Cloudflare Workflow execution
- WebSocket: Events are broadcast to connected WebSocket clients
Delivery Guarantees
- At-least-once delivery (events may be delivered more than once in rare cases)
- Events are delivered in the order they were appended to their respective streams
- Failed deliveries are retried according to the configured retry policy
Authorizations
Section titled “Authorizations ”Parameters
Section titled “ Parameters ”Path Parameters
Section titled “Path Parameters ”Event store name (e.g. “production”)
Event store name (e.g. “production”)
Request Body
Section titled “Request Body ”object
Match all event types
Prefix match (e.g., “user.*” matches “user.created”, “user.updated”, etc.)
Suffix match (e.g., “*.created” matches “user.created”, “order.created”, etc.)
Exact match (e.g., “user.created”)
Multiple event patterns to match
Optional custom ID for this subscription. If not provided, one will be generated.
object
Configuration for Durable Object subscribers
object
Configuration for retry behavior
object
Maximum number of delivery attempts before giving up
How many minutes to wait between retry attempts
The Durable Object namespace binding name in your worker
The ID of the Durable Object instance to deliver events to
object
Configuration for webhook subscribers
object
Configuration for retry behavior
object
Maximum number of delivery attempts before giving up
How many minutes to wait between retry attempts
The URL that will receive HTTP POST requests with events
Custom headers to include in the webhook request
object
Timeout in milliseconds for the webhook request
object
Configuration for queue subscribers
object
Configuration for retry behavior
object
Maximum number of delivery attempts before giving up
How many minutes to wait between retry attempts
The name of the queue to send events to
The region of the queue
Maximum number of events to batch in a single queue message
object
Configuration for Cloudflare Workflow subscribers
object
Configuration for retry behavior
object
Maximum number of delivery attempts before giving up
How many minutes to wait between retry attempts
The name of the workflow binding in your worker
object
Configuration for WebSocket subscribers
object
Configuration for retry behavior
object
Maximum number of delivery attempts before giving up
How many minutes to wait between retry attempts
The ID of the WebSocket manager to broadcast events to
The position in the message stream from which a consumer starts consuming messages when there is no prior checkpoint. Defaults to latest.
Examples
Basic webhook subscription
{ "eventFilter": "user.*", "subscriber": { "type": "webhook", "config": { "url": "https://example.com/webhooks/events", "headers": { "X-API-Key": "your-secret-key" }, "retryPolicy": { "maxAttempts": 5, "backoffMinutes": 10 } } }}Durable Object subscription
{ "eventFilter": [ "order.created", "order.updated" ], "subscriber": { "type": "durable_object", "config": { "namespace": "ORDER_PROCESSOR", "id": "order-processor-instance-1" } }}Cloudflare Workflow subscription
{ "eventFilter": "*", "subscriber": { "type": "cloudflare_workflow", "config": { "bindingName": "EVENT_WORKFLOW" } }}WebSocket subscription for real-time updates
{ "eventFilter": "notification.*", "subscriber": { "type": "websocket", "config": { "managerId": "notifications-websocket-manager" } }}Responses
Section titled “ Responses ”Subscription created successfully. Use the returned subscriptionId to manage this subscription.
object
Unique identifier for this subscription
Current status of the subscription
Additional details about the current status
object
The event store name this subscription is connected to
The event pattern this subscription is filtering on
The ID of the subscriber
The type of subscriber to receive events
When this subscription was created
When this subscription was last updated
The global position of the last successfully delivered event
Whether this is an existing subscription that was found instead of creating a new one
Human-readable message about the subscription operation
Examples
New subscription created
{ "subscriptionId": "sub_123456", "status": "ACTIVE", "eventStoreName": "production", "eventFilter": "user.*", "subscriberId": "webhook-user-events", "subscriberType": "webhook", "createdAt": "2023-10-25T15:30:45Z", "updatedAt": "2023-10-25T15:30:45Z", "lastProcessedEventGlobalPosition": 0, "isExistingSubscription": false, "message": "Successfully created new subscription (ID: webhook-user-events)."}Existing subscription found and returned
{ "subscriptionId": "sub_789012", "status": "ACTIVE", "eventStoreName": "production", "eventFilter": "user.*", "subscriberId": "existing-webhook-user-events", "subscriberType": "webhook", "createdAt": "2023-10-20T10:15:30Z", "updatedAt": "2023-10-20T10:15:30Z", "lastProcessedEventGlobalPosition": 1234, "isExistingSubscription": true, "message": "Found existing webhook subscription with the same configuration (ID: existing-webhook-user-events). Returning existing subscription instead of creating a duplicate."}Existing subscription found but has errors
{ "subscriptionId": "sub_345678", "status": "ERROR", "statusDetails": { "lastError": "Connection timeout", "lastErrorAt": "2023-10-25T14:30:00Z", "retryCount": 3 }, "eventStoreName": "production", "eventFilter": "user.*", "subscriberId": "error-webhook-user-events", "subscriberType": "webhook", "createdAt": "2023-10-25T14:00:00Z", "updatedAt": "2023-10-25T14:30:00Z", "lastProcessedEventGlobalPosition": 500, "isExistingSubscription": true, "message": "Found existing webhook subscription with the same configuration (ID: error-webhook-user-events), but it has errors. Consider fixing the configuration or check the error details."}Invalid request parameters
object
Error type
Human-readable error message
Additional error details
object
Examples
{ "error": "INVALID_CALLBACK_URL", "message": "The provided callback URL is invalid or not reachable", "details": { "callbackUrl": "https://example.com/webhooks/events" }}{ "error": "INVALID_EVENT_FILTER", "message": "The provided event filter pattern is invalid", "details": { "eventFilter": "invalid..pattern", "validPatterns": [ "*", "namespace.*", "*.event", "namespace.event" ] }}Unauthorized: Organization ID not found in authentication context
object
Error type
Human-readable error message
Additional error details
object
Examples
{ "error": "UNAUTHORIZED", "message": "Unauthorized"}Event store not found
object
Error type
Human-readable error message
Additional error details
object
Examples
{ "error": "EVENT_STORE_NOT_FOUND", "message": "The specified event store does not exist", "details": { "eventStoreName": "nonexistent" }}Internal server error
object
Error type
Human-readable error message
Additional error details