Skip to content
Browse documentation

Build

Cloudflare Queues

Forward verified events into a Cloudflare Queue with a bearer token, a scoped API token, and the Queues HTTP API.

Cloudflare Queues is a good landing point when a Worker should process events asynchronously. Hooks posts to the Queues HTTP API with the generic HTTPS destination type, so no new destination adapter is needed: the URL carries the account and queue ids, a bearer token authenticates the request, and the body template wraps the event in the shape the API expects.

  1. In the Cloudflare dashboard, create a queue (for example hooks-events).
  2. Create an API token with Queues: Edit permission, limited to that queue and the account that owns it.
  3. Copy the queue’s HTTP API URL: https://api.cloudflare.com/client/v4/accounts/<account_id>/queues/<queue_id>/messages

Keep the token out of source control. In Hooks it is stored as a write-only project secret and referenced as {{secret.…}}.

Console → Quick start → Any event → Cloudflare Queue creates an endpoint and an HTTPS destination in one step. Fill in:

Field Value
Queues API URL The …/accounts/<account_id>/queues/<queue_id>/messages URL above.
Queues API token The scoped token. Stored as a project secret and sent as a Bearer token.
Webhook signing secret A secret you also configure on the source that calls the Hooks URL.

The template sets:

  • POST to the Queues API URL.
  • Authorization: Bearer {{secret.…}} from the token field.
  • A JSON body of {"body": <event payload>, "content_type": "application/json"}.

The raw inbound body becomes the message body. If the source sends form-encoded or otherwise non-JSON payloads, change the destination body template to wrap the payload as a string — for example {"body": "{{event.payload}}", "content_type": "text/plain"} — or reshape it with the payload template syntax.

The same destination works without the template:

Terminal window
curl -X POST "https://api.hooks.events/v1/endpoints/ep_7a3k2/destinations" \
-H "Authorization: Bearer $HOOKS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/queues/$QUEUE_ID/messages",
"method": "POST",
"bodyMode": "json",
"bodyTemplate": "{\"body\": {{event.payload}}, \"content_type\": \"application/json\"}",
"auth": { "mode": "bearer", "token": "{{secret.CF_QUEUES_TOKEN}}" }
}'

Create the CF_QUEUES_TOKEN secret first; the value never appears in API responses, the console, or delivery logs.

Open Deliveries and check the newest attempt for this destination. A successful post returns 200 with a JSON result that includes the message id. The attempt record shows the status code, duration, and the (redacted) request headers.

If the queue returns 4xx, the destination fails permanently — check the account id, queue id, and token scope. 5xx, 429, and timeouts retry with the standard retry schedule; every attempt is recorded, and a dead delivery triggers the destination’s failure alert.

  • Use a token scoped to Queues write for one account. A global API key also works but grants far more than this integration needs.
  • Cloudflare Queues takes a delay_seconds field when a message should be processed later; add it to the body template if your consumer expects it.
  • Message size limits are enforced by Cloudflare. If events can be large, filter them at the destination or truncate fields in the body template before forwarding.