Skip to content
Start here

Attach Custom Domain To Bucket

client.R2.Buckets.Domains.Custom.New(ctx, bucketName, params) (*BucketDomainCustomNewResponse, error)
POST/accounts/{account_id}/r2/buckets/{bucket_name}/domains/custom

Register a new custom domain for an existing R2 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 BucketDomainCustomNewParams
AccountID param.Field[string]

Path param: Account ID.

maxLength32
Domain param.Field[string]

Body param: Name of the custom domain to be added.

Enabled param.Field[bool]

Body param: Whether to enable public bucket access at the custom domain. If undefined, the domain will be enabled.

ZoneID param.Field[string]

Body param: Zone ID of the custom domain.

Ciphers param.Field[[]string]optional

Body param: An allowlist of ciphers for TLS termination. These ciphers must be in the BoringSSL format.

MinTLS param.Field[BucketDomainCustomNewParamsMinTLS]optional

Body param: Minimum TLS Version the custom domain will accept for incoming connections. If not set, defaults to 1.0.

const BucketDomainCustomNewParamsMinTLS1_0 BucketDomainCustomNewParamsMinTLS = "1.0"
const BucketDomainCustomNewParamsMinTLS1_1 BucketDomainCustomNewParamsMinTLS = "1.1"
const BucketDomainCustomNewParamsMinTLS1_2 BucketDomainCustomNewParamsMinTLS = "1.2"
const BucketDomainCustomNewParamsMinTLS1_3 BucketDomainCustomNewParamsMinTLS = "1.3"
Jurisdiction param.Field[BucketDomainCustomNewParamsCfR2Jurisdiction]optional

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

const BucketDomainCustomNewParamsCfR2JurisdictionDefault BucketDomainCustomNewParamsCfR2Jurisdiction = "default"
const BucketDomainCustomNewParamsCfR2JurisdictionEu BucketDomainCustomNewParamsCfR2Jurisdiction = "eu"
const BucketDomainCustomNewParamsCfR2JurisdictionFedramp BucketDomainCustomNewParamsCfR2Jurisdiction = "fedramp"
ReturnsExpand Collapse
type BucketDomainCustomNewResponse struct{…}
Domain string

Domain name of the affected custom domain.

Enabled bool

Whether this bucket is publicly accessible at the specified custom domain.

Ciphers []stringoptional

An allowlist of ciphers for TLS termination. These ciphers must be in the BoringSSL format.

MinTLS BucketDomainCustomNewResponseMinTLSoptional

Minimum TLS Version the custom domain will accept for incoming connections. If not set, defaults to 1.0.

One of the following:
const BucketDomainCustomNewResponseMinTLS1_0 BucketDomainCustomNewResponseMinTLS = "1.0"
const BucketDomainCustomNewResponseMinTLS1_1 BucketDomainCustomNewResponseMinTLS = "1.1"
const BucketDomainCustomNewResponseMinTLS1_2 BucketDomainCustomNewResponseMinTLS = "1.2"
const BucketDomainCustomNewResponseMinTLS1_3 BucketDomainCustomNewResponseMinTLS = "1.3"

Attach Custom Domain To Bucket

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"),
  )
  custom, err := client.R2.Buckets.Domains.Custom.New(
    context.TODO(),
    "example-bucket",
    r2.BucketDomainCustomNewParams{
      AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
      Domain: cloudflare.F("prefix.example-domain.com"),
      Enabled: cloudflare.F(true),
      ZoneID: cloudflare.F("36ca64a6d92827b8a6b90be344bb1bfd"),
    },
  )
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", custom.Domain)
}
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    "string"
  ],
  "result": {
    "domain": "example-domain.com",
    "enabled": true,
    "ciphers": [
      "string"
    ],
    "minTLS": "1.0"
  },
  "success": true
}
Returns Examples
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    "string"
  ],
  "result": {
    "domain": "example-domain.com",
    "enabled": true,
    "ciphers": [
      "string"
    ],
    "minTLS": "1.0"
  },
  "success": true
}