Skip to content
Start here

Get Object Lifecycle Rules

client.r2.buckets.lifecycle.get(stringbucketName, LifecycleGetParams { account_id, jurisdiction } params, RequestOptionsoptions?): LifecycleGetResponse { rules }
GET/accounts/{account_id}/r2/buckets/{bucket_name}/lifecycle

Get object lifecycle rules for a bucket.

Security

API Token

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

Example:Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY
ParametersExpand Collapse
bucketName: string

Name of the bucket.

maxLength64
minLength3
params: LifecycleGetParams { account_id, jurisdiction }
account_id: string

Path param: Account ID.

maxLength32
jurisdiction?: "default" | "eu" | "fedramp"

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

One of the following:
"default"
"eu"
"fedramp"
ReturnsExpand Collapse
LifecycleGetResponse { rules }
rules?: Array<Rule>
id: string

Unique identifier for this rule.

conditions: Conditions { prefix }

Conditions that apply to all transitions of this rule.

prefix: string

Transitions will only apply to objects/uploads in the bucket that start with the given prefix, an empty prefix can be provided to scope rule to all objects/uploads.

enabled: boolean

Whether or not this rule is in effect.

abortMultipartUploadsTransition?: AbortMultipartUploadsTransition { condition }

Transition to abort ongoing multipart uploads.

condition?: Condition { maxAge, type }

Condition for lifecycle transitions to apply after an object reaches an age in seconds.

maxAge: number
type: "Age"
deleteObjectsTransition?: DeleteObjectsTransition { condition }

Transition to delete objects.

condition?: R2LifecycleAgeCondition { maxAge, type } | R2LifecycleDateCondition { date, type }

Condition for lifecycle transitions to apply after an object reaches an age in seconds.

One of the following:
R2LifecycleAgeCondition { maxAge, type }

Condition for lifecycle transitions to apply after an object reaches an age in seconds.

maxAge: number
type: "Age"
R2LifecycleDateCondition { date, type }

Condition for lifecycle transitions to apply on a specific date.

date: string
formatdate-time
type: "Date"
storageClassTransitions?: Array<StorageClassTransition>

Transitions to change the storage class of objects.

condition: R2LifecycleAgeCondition { maxAge, type } | R2LifecycleDateCondition { date, type }

Condition for lifecycle transitions to apply after an object reaches an age in seconds.

One of the following:
R2LifecycleAgeCondition { maxAge, type }

Condition for lifecycle transitions to apply after an object reaches an age in seconds.

maxAge: number
type: "Age"
R2LifecycleDateCondition { date, type }

Condition for lifecycle transitions to apply on a specific date.

date: string
formatdate-time
type: "Date"
storageClass: "InfrequentAccess"

Get Object Lifecycle Rules

import Cloudflare from 'cloudflare';

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

const lifecycle = await client.r2.buckets.lifecycle.get('example-bucket', {
  account_id: '023e105f4ecef8ad9ca31a8372d0c353',
});

console.log(lifecycle.rules);
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    "string"
  ],
  "result": {
    "rules": [
      {
        "id": "Expire all objects older than 24 hours",
        "conditions": {
          "prefix": "prefix"
        },
        "enabled": true,
        "abortMultipartUploadsTransition": {
          "condition": {
            "maxAge": 0,
            "type": "Age"
          }
        },
        "deleteObjectsTransition": {
          "condition": {
            "maxAge": 0,
            "type": "Age"
          }
        },
        "storageClassTransitions": [
          {
            "condition": {
              "maxAge": 0,
              "type": "Age"
            },
            "storageClass": "InfrequentAccess"
          }
        ]
      }
    ]
  },
  "success": true
}
Returns Examples
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    "string"
  ],
  "result": {
    "rules": [
      {
        "id": "Expire all objects older than 24 hours",
        "conditions": {
          "prefix": "prefix"
        },
        "enabled": true,
        "abortMultipartUploadsTransition": {
          "condition": {
            "maxAge": 0,
            "type": "Age"
          }
        },
        "deleteObjectsTransition": {
          "condition": {
            "maxAge": 0,
            "type": "Age"
          }
        },
        "storageClassTransitions": [
          {
            "condition": {
              "maxAge": 0,
              "type": "Age"
            },
            "storageClass": "InfrequentAccess"
          }
        ]
      }
    ]
  },
  "success": true
}