Skip to content
Start here

List Buckets

client.R2.Buckets.List(ctx, params) (*BucketListResponse, error)
GET/accounts/{account_id}/r2/buckets

Lists a page of R2 buckets in the account and selected jurisdiction. Use the returned cursor to retrieve the next page.

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 WriteWorkers R2 Storage Read
ParametersExpand Collapse
params BucketListParams
AccountID param.Field[string]

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

maxLength32
Cursor param.Field[string]Optional

Query param: Pagination cursor received during the last List Buckets call. R2 buckets are paginated using cursors instead of page numbers.

Direction param.Field[BucketListParamsDirection]Optional

Query param: Direction to order buckets.

const BucketListParamsDirectionAsc BucketListParamsDirection = "asc"
const BucketListParamsDirectionDesc BucketListParamsDirection = "desc"
NameContains param.Field[string]Optional

Query param: Bucket names to filter by. Only buckets with this phrase in their name will be returned.

Order param.Field[BucketListParamsOrder]Optional

Query param: Field to order buckets by.

const BucketListParamsOrderName BucketListParamsOrder = "name"
PerPage param.Field[float64]Optional

Query param: Maximum number of buckets to return in a single call.

maximum1000
minimum1
StartAfter param.Field[string]Optional

Query param: Bucket name to start searching after. Buckets are ordered lexicographically.

CfR2Jurisdiction param.Field[BucketListParamsCfR2Jurisdiction]Optional

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

const BucketListParamsCfR2JurisdictionDefault BucketListParamsCfR2Jurisdiction = "default"
const BucketListParamsCfR2JurisdictionEu BucketListParamsCfR2Jurisdiction = "eu"
const BucketListParamsCfR2JurisdictionUs BucketListParamsCfR2Jurisdiction = "us"
const BucketListParamsCfR2JurisdictionFedramp BucketListParamsCfR2Jurisdiction = "fedramp"
const BucketListParamsCfR2JurisdictionFedrampHigh BucketListParamsCfR2Jurisdiction = "fedramp-high"
ReturnsExpand Collapse
type BucketListResponse struct{…}
Buckets []BucketOptional
CreationDate stringOptional

Creation timestamp.

Jurisdiction BucketJurisdictionOptional

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

One of the following:
const BucketJurisdictionDefault BucketJurisdiction = "default"
const BucketJurisdictionEu BucketJurisdiction = "eu"
const BucketJurisdictionUs BucketJurisdiction = "us"
const BucketJurisdictionFedramp BucketJurisdiction = "fedramp"
const BucketJurisdictionFedrampHigh BucketJurisdiction = "fedramp-high"
Location BucketLocationOptional

Location of the bucket.

One of the following:
const BucketLocationApac BucketLocation = "apac"
const BucketLocationEeur BucketLocation = "eeur"
const BucketLocationEnam BucketLocation = "enam"
const BucketLocationWeur BucketLocation = "weur"
const BucketLocationWnam BucketLocation = "wnam"
const BucketLocationOc BucketLocation = "oc"
Name stringOptional

Name of the bucket.

maxLength64
minLength3
StorageClass BucketStorageClassOptional

Storage class for newly uploaded objects, unless specified otherwise.

One of the following:
const BucketStorageClassStandard BucketStorageClass = "Standard"
const BucketStorageClassInfrequentAccess BucketStorageClass = "InfrequentAccess"

List Buckets

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"),
  )
  buckets, err := client.R2.Buckets.List(context.TODO(), r2.BucketListParams{
    AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", buckets.Buckets)
}
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    "string"
  ],
  "result": {
    "buckets": [
      {
        "creation_date": "creation_date",
        "jurisdiction": "default",
        "location": "apac",
        "name": "example-bucket",
        "storage_class": "Standard"
      }
    ]
  },
  "success": true,
  "result_info": {
    "cursor": "1-JTdCJTIydiUyMiUzQTElMkMlMjJzdGFydEFmdGVyJTIyJTNBJTIyZGF2aWRwdWJsaWMlMjIlN0Q=",
    "per_page": 20
  }
}
Returns Examples
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    "string"
  ],
  "result": {
    "buckets": [
      {
        "creation_date": "creation_date",
        "jurisdiction": "default",
        "location": "apac",
        "name": "example-bucket",
        "storage_class": "Standard"
      }
    ]
  },
  "success": true,
  "result_info": {
    "cursor": "1-JTdCJTIydiUyMiUzQTElMkMlMjJzdGFydEFmdGVyJTIyJTNBJTIyZGF2aWRwdWJsaWMlMjIlN0Q=",
    "per_page": 20
  }
}