Skip to content
Start here

Create Event Notification Rules

client.r2.buckets.eventNotifications.update(stringqueueID, EventNotificationUpdateParams { account_id, bucket_name, rules, cfR2Jurisdiction } params, RequestOptionsoptions?): EventNotificationUpdateResponse
PUT/accounts/{account_id}/event_notifications/r2/{bucket_name}/configuration/queues/{queue_id}

Creates rules that send notifications for matching R2 object events to the specified Cloudflare Queue. Rules can filter objects by key prefix and suffix. New rules are added to any existing rules for the queue; a rule that overlaps an existing rule is rejected.

Security

API Token

The preferred authorization scheme for interacting with the Cloudflare API. Create a token.

Example:Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY
Accepted Permissions (at least one required)
Workers R2 Storage Write
ParametersExpand Collapse
queueID: string

ID of the Cloudflare Queue that receives notifications for matching R2 object events.

maxLength32
params: EventNotificationUpdateParams { account_id, bucket_name, rules, cfR2Jurisdiction }
account_id: string

Path param: Cloudflare account ID that owns the R2 resource.

maxLength32
bucket_name: string

Path param: Name of the bucket.

maxLength64
minLength3
rules: Array<Rule>

Body param: Array of rules to drive notifications.

actions: Array<"PutObject" | "CopyObject" | "DeleteObject" | 2 more>

Array of R2 object actions that will trigger notifications.

One of the following:
"PutObject"
"CopyObject"
"DeleteObject"
"CompleteMultipartUpload"
"LifecycleDeletion"
description?: string

A description that can be used to identify the event notification rule after creation.

prefix?: string

Notifications will be sent only for objects with this prefix.

suffix?: string

Notifications will be sent only for objects with this suffix.

cfR2Jurisdiction?: "default" | "eu" | "us" | 2 more

Header param: Jurisdiction where objects in this bucket are guaranteed to be stored.

One of the following:
"default"
"eu"
"us"
"fedramp"
"fedramp-high"
ReturnsExpand Collapse
EventNotificationUpdateResponse = unknown

Create Event Notification Rules

import Cloudflare from 'cloudflare';

const client = new Cloudflare({
  apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted
});

const eventNotification = await client.r2.buckets.eventNotifications.update('queue_id', {
  account_id: '023e105f4ecef8ad9ca31a8372d0c353',
  bucket_name: 'example-bucket',
  rules: [{ actions: ['PutObject', 'CopyObject'] }],
});

console.log(eventNotification);
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    "string"
  ],
  "result": {},
  "success": true
}
Returns Examples
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    "string"
  ],
  "result": {},
  "success": true
}