Table of Contents

Interface IAccountsApi

Namespace
Cloudflare.NET.Accounts
Assembly
Cloudflare.NET.dll

Defines the contract for interacting with Cloudflare Account resources.

This includes managing R2 buckets and their associated domains, as well as account-level security resources like IP Access Rules and WAF Rulesets.

public interface IAccountsApi

Properties

AccessRules

Gets the API for managing account-level IP Access Rules.

IAccountAccessRulesApi AccessRules { get; }

Property Value

IAccountAccessRulesApi

Remarks

Corresponds to the /accounts/{account_id}/firewall/access_rules/rules endpoint.

Buckets

Gets the API for managing R2 buckets and related resources.

IR2BucketsApi Buckets { get; }

Property Value

IR2BucketsApi

Remarks

Provides operations for bucket CRUD, CORS, lifecycle, custom domains, managed domains, bucket locks, Sippy migration, and temporary credentials.

D1

Gets the API for managing D1 serverless SQL databases.

ID1Api D1 { get; }

Property Value

ID1Api

Remarks

Corresponds to the `/accounts/{account_id}/d1/database` endpoint family.

D1 is Cloudflare's native serverless SQL database built on SQLite. The REST API is subject to global Cloudflare API rate limits and is best suited for administrative operations. For high-throughput query access, consider using a Worker with D1 bindings.

See Also

Kv

Gets the API for managing Workers KV namespaces and key-value pairs.

IKvApi Kv { get; }

Property Value

IKvApi

Remarks

Corresponds to the /accounts/{account_id}/storage/kv/namespaces endpoint family.

See Also

Rulesets

Gets the API for managing account-level Rulesets (e.g., WAF Custom Rules).

IAccountRulesetsApi Rulesets { get; }

Property Value

IAccountRulesetsApi

Remarks

Corresponds to the /accounts/{account_id}/rulesets endpoint family.

Methods

AttachCustomDomainAsync(string, string, string, CancellationToken)

Attaches a custom domain to an R2 bucket, allowing it to be served from a custom hostname.

[Obsolete("Use Buckets.AttachCustomDomainAsync instead. This method will be removed in a future version.")]
Task<CustomDomainResponse> AttachCustomDomainAsync(string bucketName, string hostname, string zoneId, CancellationToken cancellationToken = default)

Parameters

bucketName string

The name of the R2 bucket.

hostname string

The custom hostname to attach (e.g., "files.example.com").

zoneId string

The ID of the zone the hostname belongs to.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<CustomDomainResponse>

A task that represents the asynchronous operation. The task result contains the CustomDomainResponse from the API.

See Also

CreateAccountAsync(CreateAccountRequest, CancellationToken)

Creates a new Cloudflare account.

Note: This operation is only available to tenant administrators. Standard users will receive a permission error.

Task<Account> CreateAccountAsync(CreateAccountRequest request, CancellationToken cancellationToken = default)

Parameters

request CreateAccountRequest

The account creation parameters.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<Account>

The newly created account.

Remarks

Preview: This operation has limited test coverage.

This endpoint requires tenant admin privileges. Most users should use the Cloudflare dashboard to create accounts.

Exceptions

CloudflareApiException

Thrown when the user lacks tenant admin privileges or the request is invalid.

See Also

CreateR2BucketAsync(string, R2LocationHint?, R2Jurisdiction?, R2StorageClass?, CancellationToken)

Creates a new R2 bucket within the configured account with optional location and storage settings.

[Obsolete("Use Buckets.CreateAsync instead. This method will be removed in a future version.")]
Task<R2Bucket> CreateR2BucketAsync(string bucketName, R2LocationHint? locationHint = null, R2Jurisdiction? jurisdiction = null, R2StorageClass? storageClass = null, CancellationToken cancellationToken = default)

Parameters

bucketName string

The desired name for the new bucket. Must be unique.

locationHint R2LocationHint?

Optional location hint suggesting where the bucket's data should be stored. Use R2LocationHint constants (e.g., EastNorthAmerica).

jurisdiction R2Jurisdiction?

Optional jurisdictional restriction guaranteeing data residency. Use R2Jurisdiction constants (e.g., EuropeanUnion).

storageClass R2StorageClass?

Optional default storage class for new objects. Use R2StorageClass constants (e.g., InfrequentAccess).

cancellationToken CancellationToken

A cancellation token.

Returns

Task<R2Bucket>

A task that represents the asynchronous operation. The task result contains the R2Bucket from the Cloudflare API, detailing the created bucket.

See Also

DeleteAccountAsync(string, CancellationToken)

Permanently deletes an account and all associated resources.

Warning: This is a destructive operation that cannot be undone. All zones, Workers, R2 buckets, and other resources under the account will be permanently deleted.

Note: This operation is only available to tenant administrators.

Task<DeleteAccountResult> DeleteAccountAsync(string accountId, CancellationToken cancellationToken = default)

Parameters

accountId string

The account identifier.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<DeleteAccountResult>

The deletion result containing the deleted account's ID.

Remarks

Preview: This operation has limited test coverage.

This endpoint requires tenant admin privileges. The operation is permanent and will remove all zones and resources under the account.

Exceptions

CloudflareApiException

Thrown when the user lacks tenant admin privileges.

See Also

DeleteBucketCorsAsync(string, CancellationToken)

Deletes the CORS policy for an R2 bucket, removing all CORS rules.

[Obsolete("Use Buckets.DeleteCorsAsync instead. This method will be removed in a future version.")]
Task DeleteBucketCorsAsync(string bucketName, CancellationToken cancellationToken = default)

Parameters

bucketName string

The name of the bucket.

cancellationToken CancellationToken

A cancellation token.

Returns

Task

A task that represents the asynchronous operation.

See Also

DeleteBucketLifecycleAsync(string, CancellationToken)

Deletes the lifecycle policy for an R2 bucket, removing all lifecycle rules.

[Obsolete("Use Buckets.DeleteLifecycleAsync instead. This method will be removed in a future version.")]
Task DeleteBucketLifecycleAsync(string bucketName, CancellationToken cancellationToken = default)

Parameters

bucketName string

The name of the bucket.

cancellationToken CancellationToken

A cancellation token.

Returns

Task

A task that represents the asynchronous operation.

Remarks

Cloudflare R2 does not have a dedicated DELETE endpoint for lifecycle policies. This method removes the policy by setting an empty rules array.

See Also

DeleteR2BucketAsync(string, CancellationToken)

Deletes an R2 bucket. The bucket must be empty before it can be deleted.

[Obsolete("Use Buckets.DeleteAsync instead. This method will be removed in a future version.")]
Task DeleteR2BucketAsync(string bucketName, CancellationToken cancellationToken = default)

Parameters

bucketName string

The name of the bucket to delete.

cancellationToken CancellationToken

A cancellation token.

Returns

Task

A task that represents the asynchronous operation.

DetachCustomDomainAsync(string, string, CancellationToken)

Detaches a custom domain from an R2 bucket.

[Obsolete("Use Buckets.DetachCustomDomainAsync instead. This method will be removed in a future version.")]
Task DetachCustomDomainAsync(string bucketName, string hostname, CancellationToken cancellationToken = default)

Parameters

bucketName string

The name of the bucket.

hostname string

The custom hostname to detach.

cancellationToken CancellationToken

A cancellation token.

Returns

Task

A task that represents the asynchronous operation.

DisableDevUrlAsync(string, CancellationToken)

Disables the public r2.dev URL for a given bucket.

[Obsolete("Use Buckets.DisableManagedDomainAsync instead. This method will be removed in a future version.")]
Task DisableDevUrlAsync(string bucketName, CancellationToken cancellationToken = default)

Parameters

bucketName string

The name of the bucket to modify.

cancellationToken CancellationToken

A cancellation token.

Returns

Task

A task that represents the asynchronous operation.

GetAccountAsync(string, CancellationToken)

Gets details for a specific account.

Returns the full account object including settings and managed_by information.

Task<Account> GetAccountAsync(string accountId, CancellationToken cancellationToken = default)

Parameters

accountId string

The account identifier (32 hexadecimal characters).

cancellationToken CancellationToken

A cancellation token.

Returns

Task<Account>

The account details.

Examples

var account = await client.Accounts.GetAccountAsync(accountId);
Console.WriteLine($"Account: {account.Name}");
Console.WriteLine($"2FA Enforced: {account.Settings?.EnforceTwofactor}");
See Also

GetBucketCorsAsync(string, CancellationToken)

Gets the CORS policy for an R2 bucket.

[Obsolete("Use Buckets.GetCorsAsync instead. This method will be removed in a future version.")]
Task<BucketCorsPolicy> GetBucketCorsAsync(string bucketName, CancellationToken cancellationToken = default)

Parameters

bucketName string

The name of the bucket.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<BucketCorsPolicy>

A task that represents the asynchronous operation. The task result contains the BucketCorsPolicy with the current CORS rules.

See Also

GetBucketLifecycleAsync(string, CancellationToken)

Gets the lifecycle policy for an R2 bucket.

[Obsolete("Use Buckets.GetLifecycleAsync instead. This method will be removed in a future version.")]
Task<BucketLifecyclePolicy> GetBucketLifecycleAsync(string bucketName, CancellationToken cancellationToken = default)

Parameters

bucketName string

The name of the bucket.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<BucketLifecyclePolicy>

A task that represents the asynchronous operation. The task result contains the BucketLifecyclePolicy with the current lifecycle rules.

Remarks

Lifecycle rules determine object retention, automatic deletion, storage class transitions, and cleanup of incomplete multipart uploads. A bucket can have up to 1000 lifecycle rules.

See Also

GetCustomDomainStatusAsync(string, string, CancellationToken)

Gets the current status of a custom domain attached to a bucket, including ownership and SSL status.

[Obsolete("Use Buckets.GetCustomDomainStatusAsync instead. This method will be removed in a future version.")]
Task<CustomDomainResponse> GetCustomDomainStatusAsync(string bucketName, string hostname, CancellationToken cancellationToken = default)

Parameters

bucketName string

The name of the R2 bucket.

hostname string

The custom hostname to check.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<CustomDomainResponse>

A task that represents the asynchronous operation. The task result contains the CustomDomainResponse with the latest status.

ListAccountsAsync(ListAccountsFilters?, CancellationToken)

Lists all accounts the authenticated user has access to.

Returns a single page of results with pagination information for manual pagination control.

Task<PagePaginatedResult<Account>> ListAccountsAsync(ListAccountsFilters? filters = null, CancellationToken cancellationToken = default)

Parameters

filters ListAccountsFilters

Optional filtering and pagination options.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<PagePaginatedResult<Account>>

A page of accounts with pagination information.

Examples

var accounts = await client.Accounts.ListAccountsAsync(
  new ListAccountsFilters(PerPage: 50));

foreach (var account in accounts.Items)
{
  Console.WriteLine($"{account.Name} ({account.Type})");
}
See Also

ListAllAccountsAsync(ListAccountsFilters?, CancellationToken)

Lists all accounts the authenticated user has access to, automatically handling pagination.

This method returns an IAsyncEnumerable<T> that automatically fetches additional pages as you iterate, yielding all accounts without manual pagination handling.

IAsyncEnumerable<Account> ListAllAccountsAsync(ListAccountsFilters? filters = null, CancellationToken cancellationToken = default)

Parameters

filters ListAccountsFilters

Optional filtering options. Pagination parameters (Page) are ignored.

cancellationToken CancellationToken

A cancellation token.

Returns

IAsyncEnumerable<Account>

An async enumerable of all accessible accounts.

Examples

await foreach (var account in client.Accounts.ListAllAccountsAsync())
{
  Console.WriteLine($"{account.Id}: {account.Name}");
}
See Also

ListAllR2BucketsAsync(ListR2BucketsFilters?, CancellationToken)

Lists all R2 buckets in the account, automatically handling cursor-based pagination.

[Obsolete("Use Buckets.ListAllAsync instead. This method will be removed in a future version.")]
IAsyncEnumerable<R2Bucket> ListAllR2BucketsAsync(ListR2BucketsFilters? filters = null, CancellationToken cancellationToken = default)

Parameters

filters ListR2BucketsFilters

Optional filters for pagination. The cursor will be ignored.

cancellationToken CancellationToken

A cancellation token.

Returns

IAsyncEnumerable<R2Bucket>

An asynchronous stream of all R2 buckets in the account.

ListR2BucketsAsync(ListR2BucketsFilters?, CancellationToken)

Lists R2 buckets in the account, allowing for manual pagination control.

[Obsolete("Use Buckets.ListAsync instead. This method will be removed in a future version.")]
Task<CursorPaginatedResult<R2Bucket>> ListR2BucketsAsync(ListR2BucketsFilters? filters = null, CancellationToken cancellationToken = default)

Parameters

filters ListR2BucketsFilters

Optional filters for pagination.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<CursorPaginatedResult<R2Bucket>>

A single page of R2 buckets along with pagination information.

SetBucketCorsAsync(string, BucketCorsPolicy, CancellationToken)

Sets or updates the CORS policy for an R2 bucket.

[Obsolete("Use Buckets.SetCorsAsync instead. This method will be removed in a future version.")]
Task SetBucketCorsAsync(string bucketName, BucketCorsPolicy corsPolicy, CancellationToken cancellationToken = default)

Parameters

bucketName string

The name of the bucket.

corsPolicy BucketCorsPolicy

The CORS policy to apply to the bucket.

cancellationToken CancellationToken

A cancellation token.

Returns

Task

A task that represents the asynchronous operation.

See Also

SetBucketLifecycleAsync(string, BucketLifecyclePolicy, CancellationToken)

Sets or updates the lifecycle policy for an R2 bucket.

[Obsolete("Use Buckets.SetLifecycleAsync instead. This method will be removed in a future version.")]
Task SetBucketLifecycleAsync(string bucketName, BucketLifecyclePolicy lifecyclePolicy, CancellationToken cancellationToken = default)

Parameters

bucketName string

The name of the bucket.

lifecyclePolicy BucketLifecyclePolicy

The lifecycle policy to apply to the bucket.

cancellationToken CancellationToken

A cancellation token.

Returns

Task

A task that represents the asynchronous operation.

Remarks

Lifecycle rules can perform the following actions:

  • Delete objects after a specified age or on a specific date
  • Abort incomplete multipart uploads after a specified age
  • Transition objects to Infrequent Access storage class

Rules are processed within 24 hours of being set. Maximum of 1000 rules per bucket.

See Also

UpdateAccountAsync(string, UpdateAccountRequest, CancellationToken)

Updates an existing account's name and/or settings.

Both the name and settings can be updated in a single request.

Task<Account> UpdateAccountAsync(string accountId, UpdateAccountRequest request, CancellationToken cancellationToken = default)

Parameters

accountId string

The account identifier.

request UpdateAccountRequest

The update parameters.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<Account>

The updated account.

Examples

var updated = await client.Accounts.UpdateAccountAsync(accountId,
  new UpdateAccountRequest(
    Name: "My Company Production",
    Settings: new AccountSettings(EnforceTwofactor: true)));
See Also