Skip to content
Start here

Create Event Notification Rules

client.R2.Buckets.EventNotifications.Update(ctx, bucketName, queueID, params) (*BucketEventNotificationUpdateResponse, error)
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
bucketName string

Name of the bucket.

maxLength64
minLength3
queueID string

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

maxLength32
params BucketEventNotificationUpdateParams
AccountID param.Field[string]

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

maxLength32
Rules param.Field[[]BucketEventNotificationUpdateParamsRule]

Body param: Array of rules to drive notifications.

Actions []BucketEventNotificationUpdateParamsRulesAction

Array of R2 object actions that will trigger notifications.

One of the following:
const BucketEventNotificationUpdateParamsRulesActionPutObject BucketEventNotificationUpdateParamsRulesAction = "PutObject"
const BucketEventNotificationUpdateParamsRulesActionCopyObject BucketEventNotificationUpdateParamsRulesAction = "CopyObject"
const BucketEventNotificationUpdateParamsRulesActionDeleteObject BucketEventNotificationUpdateParamsRulesAction = "DeleteObject"
const BucketEventNotificationUpdateParamsRulesActionCompleteMultipartUpload BucketEventNotificationUpdateParamsRulesAction = "CompleteMultipartUpload"
const BucketEventNotificationUpdateParamsRulesActionLifecycleDeletion BucketEventNotificationUpdateParamsRulesAction = "LifecycleDeletion"
Description stringOptional

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

Prefix stringOptional

Notifications will be sent only for objects with this prefix.

Suffix stringOptional

Notifications will be sent only for objects with this suffix.

CfR2Jurisdiction param.Field[BucketEventNotificationUpdateParamsCfR2Jurisdiction]Optional

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

const BucketEventNotificationUpdateParamsCfR2JurisdictionDefault BucketEventNotificationUpdateParamsCfR2Jurisdiction = "default"
const BucketEventNotificationUpdateParamsCfR2JurisdictionEu BucketEventNotificationUpdateParamsCfR2Jurisdiction = "eu"
const BucketEventNotificationUpdateParamsCfR2JurisdictionUs BucketEventNotificationUpdateParamsCfR2Jurisdiction = "us"
const BucketEventNotificationUpdateParamsCfR2JurisdictionFedramp BucketEventNotificationUpdateParamsCfR2Jurisdiction = "fedramp"
const BucketEventNotificationUpdateParamsCfR2JurisdictionFedrampHigh BucketEventNotificationUpdateParamsCfR2Jurisdiction = "fedramp-high"
ReturnsExpand Collapse
type BucketEventNotificationUpdateResponse interface{…}

Create Event Notification Rules

package main

import (
  "context"
  "fmt"

  "github.com/cloudflare/cloudflare-go"
  "github.com/cloudflare/cloudflare-go/option"
  "github.com/cloudflare/cloudflare-go/r2"
)

func main() {
  client := cloudflare.NewClient(
    option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"),
  )
  eventNotification, err := client.R2.Buckets.EventNotifications.Update(
    context.TODO(),
    "example-bucket",
    "queue_id",
    r2.BucketEventNotificationUpdateParams{
      AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
      Rules: cloudflare.F([]r2.BucketEventNotificationUpdateParamsRule{r2.BucketEventNotificationUpdateParamsRule{
        Actions: cloudflare.F([]r2.BucketEventNotificationUpdateParamsRulesAction{r2.BucketEventNotificationUpdateParamsRulesActionPutObject, r2.BucketEventNotificationUpdateParamsRulesActionCopyObject}),
      }}),
    },
  )
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", 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
}